-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-supabase.ts
More file actions
executable file
·92 lines (73 loc) · 2.87 KB
/
setup-supabase.ts
File metadata and controls
executable file
·92 lines (73 loc) · 2.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env bun
/**
* This script helps set up Supabase tables for the WebRTC screen share app.
*
* Since Supabase doesn't allow creating tables via the REST API with anon key,
* this script will:
* 1. Verify your Supabase connection
* 2. Display the SQL schema you need to run
* 3. Optionally open the Supabase SQL editor for you
*/
import { createClient } from "@supabase/supabase-js";
const supabaseUrl = process.env.BUN_PUBLIC_SUPABASE_URL;
const supabaseAnonKey = process.env.BUN_PUBLIC_SUPABASE_ANON_KEY;
if (!supabaseUrl || !supabaseAnonKey) {
console.error("❌ Missing Supabase environment variables!");
console.error("Please set BUN_PUBLIC_SUPABASE_URL and BUN_PUBLIC_SUPABASE_ANON_KEY in .env.local");
process.exit(1);
}
const supabase = createClient(supabaseUrl, supabaseAnonKey);
async function checkTables() {
console.log("🔍 Checking if tables exist...\n");
// Try to query the offers table
const { data: offersData, error: offersError } = await supabase
.from("offers")
.select("id")
.limit(1);
const { data: answersData, error: answersError } = await supabase
.from("answers")
.select("id")
.limit(1);
if (offersError && offersError.code === "PGRST116") {
console.log("❌ 'offers' table does not exist");
} else if (offersError) {
console.log(`⚠️ Error checking 'offers' table: ${offersError.message}`);
} else {
console.log("✅ 'offers' table exists");
}
if (answersError && answersError.code === "PGRST116") {
console.log("❌ 'answers' table does not exist");
} else if (answersError) {
console.log(`⚠️ Error checking 'answers' table: ${answersError.message}`);
} else {
console.log("✅ 'answers' table exists");
}
return !offersError && !answersError;
}
async function main() {
console.log("🚀 Supabase Setup Helper\n");
console.log(`📍 Supabase URL: ${supabaseUrl}\n`);
const tablesExist = await checkTables();
if (tablesExist) {
console.log("\n✅ All tables exist! You're good to go!");
return;
}
console.log("\n📋 To create the tables, run this SQL in your Supabase SQL Editor:\n");
console.log("─".repeat(60));
const fs = await import("fs");
const sql = fs.readFileSync("./supabase-schema.sql", "utf-8");
console.log(sql);
console.log("─".repeat(60));
console.log("\n📝 Steps:");
console.log("1. Go to your Supabase dashboard: https://supabase.com/dashboard");
console.log("2. Select your project");
console.log("3. Go to SQL Editor");
console.log("4. Paste the SQL above and click 'Run'");
console.log("\n🔗 Or open directly:");
const projectRef = supabaseUrl.match(/https:\/\/([^.]+)\.supabase\.co/)?.[1];
if (projectRef) {
console.log(` https://supabase.com/dashboard/project/${projectRef}/sql`);
}
console.log("\n✨ After running the SQL, restart your dev server and try again!");
}
main().catch(console.error);