-
Notifications
You must be signed in to change notification settings - Fork 1
Remove obsolete Docker/Buildkite infra, update to Supabase-based local dev #60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
6ff0994
f19696f
a3ff7f9
88ab683
c6e43c6
ec8f929
0d593fb
6186222
c82b0da
5461d29
c5142c1
a57ba7e
9006441
7fe04ee
196385a
73bfa24
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| import { loadEnvConfig } from '@next/env'; | ||
| import * as fs from 'fs/promises'; | ||
| import * as path from 'path'; | ||
| import pg from 'pg'; | ||
| import { DatabaseError } from 'pg-protocol'; | ||
|
|
||
| const projectDir = process.cwd(); | ||
| loadEnvConfig(projectDir); | ||
|
|
||
| /** | ||
| * Creates the test database and applies the schema. | ||
| * This runs once before the entire test suite, ensuring tests use a separate database | ||
| * from the local dev environment. | ||
| */ | ||
| export default async function globalSetup() { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @copilot this function isn't actually deleting anything, and is still looking at the 'public' schema instead of a separate test one
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 7fe04ee. Tests now use a separate
Dev data in the |
||
| const testDb = process.env.PGDATABASE; | ||
| const host = process.env.PGHOST; | ||
| const port = process.env.PGPORT; | ||
| const user = process.env.PGUSER; | ||
| const password = process.env.PGPASSWORD; | ||
|
|
||
| if (!testDb || !host || !port || !user || !password) { | ||
| throw new Error('Missing required PG* environment variables for test setup'); | ||
| } | ||
| if (!/^[a-zA-Z0-9_]+$/.test(testDb)) { | ||
| throw new Error(`Invalid test database name: ${testDb}`); | ||
| } | ||
|
|
||
| // Connect to the default `postgres` database to create the test database | ||
| const adminPool = new pg.Pool({ | ||
| host, | ||
| port: Number(port), | ||
| database: 'postgres', | ||
| user, | ||
| password, | ||
| }); | ||
|
|
||
| try { | ||
| const exists = await adminPool.query(`SELECT 1 FROM pg_database WHERE datname = $1`, [testDb]); | ||
| if (exists.rows.length === 0) { | ||
| await adminPool.query(`CREATE DATABASE "${testDb}"`); | ||
| } | ||
| } finally { | ||
| await adminPool.end(); | ||
| } | ||
|
|
||
| // Connect to the test database and apply the schema | ||
| const testPool = new pg.Pool({ | ||
| host, | ||
| port: Number(port), | ||
| database: testDb, | ||
| user, | ||
| password, | ||
| }); | ||
|
|
||
| try { | ||
| const schemasDir = path.resolve(__dirname, '../../supabase/schemas'); | ||
| // Apply schemas in order matching supabase config.toml | ||
| const schemaFiles = ['maps.sql', 'users.sql', 'favorites.sql', 'functions.sql', 'misc.sql']; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. avoiding recreating the test db or manually applying schema changes in a TS file. if possible, run a shell script that uses the |
||
| for (const file of schemaFiles) { | ||
| const filePath = path.join(schemasDir, file); | ||
| try { | ||
| const sql = await fs.readFile(filePath, 'utf-8'); | ||
| await testPool.query(sql); | ||
| } catch (e: unknown) { | ||
| // 42P07 = duplicate_table, 42710 = duplicate_object — schema already applied | ||
| if (e instanceof DatabaseError && (e.code === '42P07' || e.code === '42710')) { | ||
| continue; | ||
| } | ||
| console.warn(`Warning: failed to apply ${file}:`, e); | ||
| } | ||
| } | ||
| } finally { | ||
| await testPool.end(); | ||
| } | ||
| } | ||
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
leave these keys out, they should be supplied by the user