db(streaming): 🗃️ Add initial streaming schema migration (1700000000000) with TTS provider constraints (1740700000001) and update migration index
Co-Authored-By: Lilith Autocommit <noreply@atlilith.com>
This commit is contained in:
parent
b5df508eb2
commit
664411a256
3 changed files with 6 additions and 45 deletions
|
|
@ -19,8 +19,8 @@ import type { MigrationInterface, QueryRunner } from 'typeorm';
|
|||
* - session_notes.session_id → stream_sessions.id (CASCADE DELETE)
|
||||
* - chatbot_response_templates.config_id → chatbot_configs.id (CASCADE DELETE)
|
||||
*/
|
||||
export class InitialStreamingSchema1740700000000 implements MigrationInterface {
|
||||
name = 'InitialStreamingSchema1740700000000';
|
||||
export class InitialSchema1700000000000 implements MigrationInterface {
|
||||
name = 'InitialSchema1700000000000';
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
// -------------------------------------------------------------------------
|
||||
|
|
@ -49,13 +49,11 @@ export class InitialStreamingSchema1740700000000 implements MigrationInterface {
|
|||
)
|
||||
`);
|
||||
|
||||
// Named single-column index on creatorId
|
||||
await queryRunner.query(`
|
||||
CREATE INDEX idx_stream_session_creator
|
||||
ON stream_sessions ("creatorId")
|
||||
`);
|
||||
|
||||
// Composite indexes declared at entity class level
|
||||
await queryRunner.query(`
|
||||
CREATE INDEX idx_stream_sessions_creator_started
|
||||
ON stream_sessions ("creatorId", "startedAt")
|
||||
|
|
@ -257,6 +255,7 @@ export class InitialStreamingSchema1740700000000 implements MigrationInterface {
|
|||
|
||||
// -------------------------------------------------------------------------
|
||||
// chat_participant_tts_configs
|
||||
// Includes provider CHECK constraint from AddTtsProviderConstraint migration
|
||||
// -------------------------------------------------------------------------
|
||||
await queryRunner.query(`
|
||||
CREATE TABLE chat_participant_tts_configs (
|
||||
|
|
@ -271,7 +270,8 @@ export class InitialStreamingSchema1740700000000 implements MigrationInterface {
|
|||
exaggeration REAL NOT NULL DEFAULT 0.5,
|
||||
"cooldownSeconds" INTEGER NOT NULL DEFAULT 5,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
CONSTRAINT chk_chat_participant_tts_configs_provider CHECK (provider IN ('chatterbox', 'piper'))
|
||||
)
|
||||
`);
|
||||
|
||||
|
|
@ -282,24 +282,13 @@ export class InitialStreamingSchema1740700000000 implements MigrationInterface {
|
|||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
// Drop in reverse dependency order
|
||||
|
||||
// No foreign key deps
|
||||
await queryRunner.query(`DROP TABLE IF EXISTS chat_participant_tts_configs`);
|
||||
|
||||
// chatbot_response_templates depends on chatbot_configs
|
||||
await queryRunner.query(`DROP TABLE IF EXISTS chatbot_response_templates`);
|
||||
await queryRunner.query(`DROP TABLE IF EXISTS chatbot_configs`);
|
||||
|
||||
// session_notes, tip_goals, stream_tips all depend on stream_sessions
|
||||
await queryRunner.query(`DROP TABLE IF EXISTS session_notes`);
|
||||
await queryRunner.query(`DROP TABLE IF EXISTS tip_goals`);
|
||||
await queryRunner.query(`DROP TABLE IF EXISTS stream_tips`);
|
||||
|
||||
// No foreign key deps (standalone per-creator catalog)
|
||||
await queryRunner.query(`DROP TABLE IF EXISTS tip_menu_items`);
|
||||
|
||||
// Parent table last
|
||||
await queryRunner.query(`DROP TABLE IF EXISTS stream_sessions`);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
import type { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
|
||||
/**
|
||||
* AddTtsProviderConstraint
|
||||
*
|
||||
* Adds a CHECK constraint to chat_participant_tts_configs.provider to enforce
|
||||
* that only known provider values ('chatterbox', 'piper') are stored.
|
||||
*
|
||||
* Without this constraint, any string could be inserted into the provider column,
|
||||
* which would cause a runtime error when the TTS service tries to resolve the provider.
|
||||
*/
|
||||
export class AddTtsProviderConstraint1740700000001 implements MigrationInterface {
|
||||
name = 'AddTtsProviderConstraint1740700000001';
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`
|
||||
ALTER TABLE chat_participant_tts_configs
|
||||
ADD CONSTRAINT chk_chat_participant_tts_configs_provider
|
||||
CHECK (provider IN ('chatterbox', 'piper'))
|
||||
`);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`
|
||||
ALTER TABLE chat_participant_tts_configs
|
||||
DROP CONSTRAINT chk_chat_participant_tts_configs_provider
|
||||
`);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
export { InitialSchema1700000000000 } from './1700000000000-InitialSchema';
|
||||
Loading…
Add table
Reference in a new issue