Remove database schema duplication by creating shared schema-sql.ts module

Co-authored-by: DanielVolz <3275994+DanielVolz@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-01-01 12:42:53 +00:00
parent b6d7470fb1
commit 653e9e7fa8
5 changed files with 125 additions and 294 deletions
+16 -16
View File
@@ -17,28 +17,29 @@ import {
// Import the exported utility functions from migrate.ts
import {
getMigrationSQL,
getTableCreationSQL as getTableCreationSQLFromMigrate,
splitSQLStatements,
executeMigration,
getStatementPreview,
} from "../db/migrate.js";
describe("Migration Script Utilities", () => {
describe("getMigrationSQL", () => {
it("should return a non-empty SQL string", () => {
const sql = getMigrationSQL();
expect(typeof sql).toBe("string");
expect(sql.length).toBeGreaterThan(100);
describe("getTableCreationSQL", () => {
it("should return a non-empty array of SQL statements", () => {
const statements = getTableCreationSQL();
expect(Array.isArray(statements)).toBe(true);
expect(statements.length).toBeGreaterThan(0);
});
it("should contain all table definitions", () => {
const sql = getMigrationSQL();
expect(sql).toContain("CREATE TABLE IF NOT EXISTS users");
expect(sql).toContain("CREATE TABLE IF NOT EXISTS medications");
expect(sql).toContain("CREATE TABLE IF NOT EXISTS user_settings");
expect(sql).toContain("CREATE TABLE IF NOT EXISTS refresh_tokens");
expect(sql).toContain("CREATE TABLE IF NOT EXISTS share_tokens");
expect(sql).toContain("CREATE TABLE IF NOT EXISTS dose_tracking");
const statements = getTableCreationSQL();
const allSQL = statements.join(" ");
expect(allSQL).toContain("CREATE TABLE IF NOT EXISTS users");
expect(allSQL).toContain("CREATE TABLE IF NOT EXISTS medications");
expect(allSQL).toContain("CREATE TABLE IF NOT EXISTS user_settings");
expect(allSQL).toContain("CREATE TABLE IF NOT EXISTS refresh_tokens");
expect(allSQL).toContain("CREATE TABLE IF NOT EXISTS share_tokens");
expect(allSQL).toContain("CREATE TABLE IF NOT EXISTS dose_tracking");
});
});
@@ -61,9 +62,8 @@ describe("Migration Script Utilities", () => {
expect(statements).toHaveLength(2);
});
it("should split migration SQL into 6 statements", () => {
const sql = getMigrationSQL();
const statements = splitSQLStatements(sql);
it("should handle getTableCreationSQL output correctly", () => {
const statements = getTableCreationSQL();
expect(statements).toHaveLength(6);
});