Adding migrations and lot of work. Starting work on the demo scope
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import path from 'node:path'
|
||||
import fs from 'node:fs/promises'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
import pg from 'pg'
|
||||
import { afterAll, beforeAll, describe, expect, it } from 'vitest'
|
||||
@@ -31,9 +32,10 @@ suite('PostgreSQL migrations', () => {
|
||||
|
||||
it('applies every migration transactionally and is idempotent', async () => {
|
||||
const migrationsDir = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..', 'migrations')
|
||||
const migrationCount = (await fs.readdir(migrationsDir)).filter(name => /^\d+.*\.sql$/.test(name)).length
|
||||
const firstRun: string[] = []
|
||||
await runMigrations(testDatabaseUrl, migrationsDir, message => firstRun.push(message))
|
||||
expect(firstRun.filter(message => message.startsWith('apply '))).toHaveLength(24)
|
||||
expect(firstRun.filter(message => message.startsWith('apply '))).toHaveLength(migrationCount)
|
||||
|
||||
const client = new Client({ connectionString: testDatabaseUrl })
|
||||
await client.connect()
|
||||
@@ -46,10 +48,13 @@ suite('PostgreSQL migrations', () => {
|
||||
'board_views', 'timeline_views',
|
||||
'mysteries', 'npcs', 'npc_poses', 'playthroughs',
|
||||
'story_nodes', 'story_node_terminals', 'utterances',
|
||||
'level_flags', 'document_flag_requirements', 'level_seen_documents', 'achievements',
|
||||
'asset_text_extractions', 'evidence_match_rules', 'evidence_match_anchors',
|
||||
'evidence_match_evaluations', 'evidence_match_anchor_evaluations',
|
||||
]))
|
||||
expect(tableNames).not.toEqual(expect.arrayContaining(['cases', 'widgets', 'widget_relations', 'cutscenes', 'dialogue_steps', 'mystery_chapters', 'seen_dialogue']))
|
||||
const ledger = await client.query<{ count: string }>('SELECT COUNT(*)::text AS count FROM osint.schema_migrations')
|
||||
expect(ledger.rows[0].count).toBe('24')
|
||||
expect(ledger.rows[0].count).toBe(String(migrationCount))
|
||||
const connectionColumns = await client.query<{ column_name: string }>(`SELECT column_name FROM information_schema.columns WHERE table_schema='osint' AND table_name='exhibit_connections'`)
|
||||
expect(connectionColumns.rows.map(row => row.column_name)).toEqual(expect.arrayContaining(['label', 'tightness', 'tag_style', 'tag_position_percent', 'tag_lateral_offset']))
|
||||
const eventOccurrence = await client.query<{ is_nullable: string }>(`SELECT is_nullable FROM information_schema.columns WHERE table_schema='osint' AND table_name='event_exhibits' AND column_name='occurred_at'`)
|
||||
@@ -58,7 +63,7 @@ suite('PostgreSQL migrations', () => {
|
||||
|
||||
const secondRun: string[] = []
|
||||
await runMigrations(testDatabaseUrl, migrationsDir, message => secondRun.push(message))
|
||||
expect(secondRun.filter(message => message.startsWith('skip '))).toHaveLength(24)
|
||||
expect(secondRun.filter(message => message.startsWith('skip '))).toHaveLength(migrationCount)
|
||||
expect(secondRun.some(message => message.startsWith('apply '))).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user