Skip to content

Commit

Permalink
fix(migrate): removes pragma from migration, adds to seed an global s…
Browse files Browse the repository at this point in the history
…etup
  • Loading branch information
NGimbal committed Feb 21, 2024
1 parent 4ef05f5 commit 89de11b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 0 additions & 2 deletions prisma/migrations/20230914194400_init/migration.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
PRAGMA journal_mode = WAL;

-- CreateTable
CREATE TABLE "User" (
"id" TEXT NOT NULL PRIMARY KEY,
Expand Down
4 changes: 4 additions & 0 deletions prisma/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ async function seed() {
await cleanupDb(prisma)
console.timeEnd('🧹 Cleaned up the database...')

prisma.$queryRaw`PRAGMA journal_mode = WAL;`.catch(e => {
console.error('Error setting journal mode:', e)
})

console.time('🔑 Created permissions...')
const entities = ['user', 'note']
const actions = ['create', 'read', 'update', 'delete']
Expand Down
15 changes: 15 additions & 0 deletions tests/setup/global-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export const BASE_DATABASE_PATH = path.join(
`./tests/prisma/base.db`,
)

const SCHEMA_PATH = path.join(process.cwd(), './prisma/schema.prisma')

export async function setup() {
const databaseExists = await fsExtra.pathExists(BASE_DATABASE_PATH)
if (databaseExists) return
Expand All @@ -21,4 +23,17 @@ export async function setup() {
},
},
)

await execaCommand(
`prisma db execute --stdin --schema ${SCHEMA_PATH} | echo "PRAGMA journal_mode = WAL"`,
{
stdio: 'inherit',
env: {
...process.env,
DATABASE_URL: `file:${BASE_DATABASE_PATH}`,
},
},
).catch(e => {
console.error('Error setting journal mode:', e)
})
}

0 comments on commit 89de11b

Please sign in to comment.