20251121_create_scripts_table.sql 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. -- Migration: create `scripts` table (destructive, does NOT preserve old `sql_scripts` data)
  2. -- Generated: 2025-11-21
  3. PRAGMA foreign_keys = OFF;
  4. BEGIN TRANSACTION;
  5. -- Drop legacy table if exists (destructive)
  6. DROP TABLE IF EXISTS sql_scripts;
  7. -- Create new `scripts` table with extended columns
  8. CREATE TABLE IF NOT EXISTS scripts (
  9. id TEXT PRIMARY KEY,
  10. connection_id TEXT NOT NULL,
  11. group_id TEXT NOT NULL,
  12. name TEXT NOT NULL,
  13. description TEXT,
  14. content TEXT,
  15. favorite INTEGER DEFAULT 0,
  16. language TEXT DEFAULT '',
  17. metadata TEXT DEFAULT '{}', -- JSON object as TEXT
  18. tags TEXT DEFAULT '[]', -- JSON array as TEXT
  19. enabled INTEGER DEFAULT 1,
  20. owner TEXT DEFAULT '',
  21. checksum TEXT DEFAULT '',
  22. execution_count INTEGER DEFAULT 0,
  23. last_executed TEXT,
  24. last_run_status TEXT DEFAULT '',
  25. created_at DATETIME,
  26. updated_at DATETIME
  27. );
  28. -- Create index for lookup by connection
  29. CREATE INDEX IF NOT EXISTS idx_scripts_connection_id ON scripts(connection_id);
  30. CREATE INDEX IF NOT EXISTS idx_scripts_group_id ON scripts(group_id);
  31. COMMIT;
  32. PRAGMA foreign_keys = ON;