diff options
| author | Dhravya Shah <[email protected]> | 2025-01-20 17:49:19 -0700 |
|---|---|---|
| committer | Dhravya Shah <[email protected]> | 2025-01-20 17:50:45 -0700 |
| commit | 47904011de646b92b1f3774f9a30bcfa118c5dc4 (patch) | |
| tree | ab0e5e79c4ad5465ceeedc9b4015be2d9d01be45 /apps/backend/scripts | |
| parent | Merge pull request #295 from supermemoryai/extension/duplicate-save-fix (diff) | |
| download | supermemory-47904011de646b92b1f3774f9a30bcfa118c5dc4.tar.xz supermemory-47904011de646b92b1f3774f9a30bcfa118c5dc4.zip | |
Supermemory v2 Release 🚀
Diffstat (limited to 'apps/backend/scripts')
| -rw-r--r-- | apps/backend/scripts/migrate.ts | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/apps/backend/scripts/migrate.ts b/apps/backend/scripts/migrate.ts new file mode 100644 index 00000000..4f8db70d --- /dev/null +++ b/apps/backend/scripts/migrate.ts @@ -0,0 +1,36 @@ +import { config } from "dotenv"; +import { drizzle } from "drizzle-orm/postgres-js"; +import { migrate } from "drizzle-orm/postgres-js/migrator"; +import process from "node:process"; +import postgres from "postgres"; + +config(); + +if (!process.env.DATABASE_URL) { + throw new Error("DATABASE_URL is not set"); +} + +const connectionString = process.env.DATABASE_URL!; + +console.log("Connecting to:", connectionString.replace(/:[^:@]+@/, ":****@")); // Log sanitized connection string + +const migrationClient = postgres(connectionString, { max: 1 }); + +async function main() { + console.log("Running migrations..."); + + try { + const db = drizzle(migrationClient); + await migrate(db, { migrationsFolder: "./drizzle" }); + console.log("Migrations completed!"); + } catch (error) { + console.error("Migration failed:", error); + } finally { + await migrationClient.end(); + } +} + +main().catch((err) => { + console.error("Unexpected error:", err); + process.exit(1); +}); |