mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-02-16 10:42:08 +00:00
bug fix - Fixed error in cleanDatabase that would cause drift
Added an extra line to ensure the query does not include the migration table. This kept on getting cleared. Reintroduced shadow db to detect drift.
This commit is contained in:
9
src/config/env/index.ts
vendored
9
src/config/env/index.ts
vendored
@@ -26,6 +26,7 @@ const envSchema = z.object({
|
|||||||
POSTGRES_PASSWORD: z.string(),
|
POSTGRES_PASSWORD: z.string(),
|
||||||
POSTGRES_DATABASE: z.string(),
|
POSTGRES_DATABASE: z.string(),
|
||||||
POSTGRES_HOST: z.string(),
|
POSTGRES_HOST: z.string(),
|
||||||
|
SHADOW_DATABASE_URL: z.string().url(),
|
||||||
|
|
||||||
NODE_ENV: z.enum(['development', 'production', 'test']),
|
NODE_ENV: z.enum(['development', 'production', 'test']),
|
||||||
SPARKPOST_API_KEY: z.string(),
|
SPARKPOST_API_KEY: z.string(),
|
||||||
@@ -187,6 +188,14 @@ export const POSTGRES_DATABASE = parsed.data.POSTGRES_DATABASE;
|
|||||||
*/
|
*/
|
||||||
export const POSTGRES_HOST = parsed.data.POSTGRES_HOST;
|
export const POSTGRES_HOST = parsed.data.POSTGRES_HOST;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The URL of another PostgreSQL database to shadow.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* 'postgresql://user:password@host:5432/database';
|
||||||
|
*/
|
||||||
|
export const SHADOW_DATABASE_URL = parsed.data.SHADOW_DATABASE_URL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Node environment.
|
* Node environment.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -6,9 +6,10 @@ generator client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
datasource db {
|
datasource db {
|
||||||
provider = "postgresql"
|
provider = "postgresql"
|
||||||
url = env("POSTGRES_PRISMA_URL") // uses connection pooling
|
url = env("POSTGRES_PRISMA_URL") // uses connection pooling
|
||||||
directUrl = env("POSTGRES_URL_NON_POOLING") // uses a direct connection
|
directUrl = env("POSTGRES_URL_NON_POOLING") // uses a direct connection
|
||||||
|
shadowDatabaseUrl = env("SHADOW_DATABASE_URL")
|
||||||
}
|
}
|
||||||
|
|
||||||
model User {
|
model User {
|
||||||
|
|||||||
@@ -13,8 +13,9 @@ const cleanDatabase = async () => {
|
|||||||
DO $$
|
DO $$
|
||||||
DECLARE
|
DECLARE
|
||||||
statements CURSOR FOR
|
statements CURSOR FOR
|
||||||
SELECT tablename FROM pg_tables
|
SELECT tablename FROM pg_tables
|
||||||
WHERE schemaname = 'public';
|
WHERE schemaname = 'public'
|
||||||
|
AND tablename != '_prisma_migrations';
|
||||||
BEGIN
|
BEGIN
|
||||||
FOR statement IN statements LOOP
|
FOR statement IN statements LOOP
|
||||||
EXECUTE 'TRUNCATE TABLE ' || quote_ident(statement.tablename) || ' CASCADE;';
|
EXECUTE 'TRUNCATE TABLE ' || quote_ident(statement.tablename) || ' CASCADE;';
|
||||||
|
|||||||
Reference in New Issue
Block a user