Re-pushing an edited route to Wahoo now updates the existing remote route via PUT against the stored remote_id instead of POSTing a new copy. external_id drops the version suffix and identifies the logical route. sync_pushes is keyed by (user, route, provider) and tracks last_pushed_version for the "local newer" UI state. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
37 lines
1.2 KiB
TypeScript
37 lines
1.2 KiB
TypeScript
// Runs hand-written SQL data migrations from packages/db/migrations/*.sql in
|
|
// lexical order. Each file is expected to be idempotent (safe to re-run);
|
|
// there is no migrations table.
|
|
//
|
|
// Why this exists: we use `drizzle-kit push --force` for schema, which is
|
|
// fine for column adds and renames but unsafe when a unique-key change
|
|
// requires collapsing existing rows first. The wahoo-route-update change is
|
|
// the first such case.
|
|
import { readdirSync, readFileSync } from "node:fs";
|
|
import path from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
import postgres from "postgres";
|
|
|
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
const migrationsDir = path.resolve(__dirname, "..", "migrations");
|
|
|
|
async function main() {
|
|
const url = process.env.DATABASE_URL ?? "postgres://trails:trails@localhost:5432/trails";
|
|
const sql = postgres(url);
|
|
try {
|
|
const files = readdirSync(migrationsDir)
|
|
.filter((f) => f.endsWith(".sql"))
|
|
.sort();
|
|
for (const f of files) {
|
|
const body = readFileSync(path.join(migrationsDir, f), "utf8");
|
|
console.log(`[migrate-data] applying ${f}`);
|
|
await sql.unsafe(body);
|
|
}
|
|
} finally {
|
|
await sql.end();
|
|
}
|
|
}
|
|
|
|
main().catch((err) => {
|
|
console.error(err);
|
|
process.exit(1);
|
|
});
|