46 lines
1.5 KiB
TypeScript
46 lines
1.5 KiB
TypeScript
import { createClient } from '@supabase/supabase-js'
|
|
import * as fs from 'fs'
|
|
import * as path from 'path'
|
|
|
|
const envPath = path.join(process.cwd(), '.env.local')
|
|
const envContent = fs.readFileSync(envPath, 'utf-8')
|
|
const envVars: Record<string, string> = {}
|
|
envContent.split('\n').forEach(line => {
|
|
const parts = line.split('=')
|
|
if (parts.length >= 2) {
|
|
envVars[parts[0].trim()] = parts.slice(1).join('=').trim()
|
|
}
|
|
})
|
|
|
|
const supabaseUrl = envVars.NEXT_PUBLIC_SUPABASE_URL
|
|
const supabaseAnonKey = envVars.NEXT_PUBLIC_SUPABASE_ANON_KEY
|
|
const supabase = createClient(supabaseUrl, supabaseAnonKey)
|
|
|
|
async function listTables() {
|
|
console.log('Listing tables from Supabase...')
|
|
// We can query schema tables via rpc or a query, or select from some common tables
|
|
// To list tables via PostgREST, we can try to query a non-existent table and see the hint or query pg_class
|
|
// Actually, let's query the supabase API or look at common tables
|
|
const tables = [
|
|
'akun_balita',
|
|
'hasil_stunting_balita',
|
|
'cetak_balita',
|
|
'detail_posyandu',
|
|
'petugas_posyandu',
|
|
'petugas_posyandu_lokal',
|
|
'jadwal_posyandu',
|
|
'posyandu_reviews',
|
|
'ulasan_posyandu'
|
|
]
|
|
for (const table of tables) {
|
|
const { error } = await supabase.from(table).select('*').limit(1)
|
|
if (error) {
|
|
console.log(`Table "${table}": ERROR (${error.message})`)
|
|
} else {
|
|
console.log(`Table "${table}": EXISTS`)
|
|
}
|
|
}
|
|
}
|
|
|
|
listTables()
|