import { BaseMigration } from './base-migration.ts';
import type { TQueryFunction } from '../types.ts';

export class Migration018HostedAppLifecycle extends BaseMigration {
  readonly version = 18;
  readonly description = 'Add hosted app lifecycle state';

  up(query: TQueryFunction): void {
    query(`
      CREATE TABLE IF NOT EXISTS hosted_app_lifecycle (
        id INTEGER PRIMARY KEY AUTOINCREMENT,
        service_id INTEGER NOT NULL UNIQUE,
        app_instance_id TEXT NOT NULL UNIQUE,
        control_token TEXT NOT NULL,
        host_type TEXT NOT NULL,
        state_json TEXT NOT NULL,
        created_at INTEGER NOT NULL,
        updated_at INTEGER NOT NULL,
        FOREIGN KEY (service_id) REFERENCES services(id) ON DELETE CASCADE
      )
    `);
  }
}
