lnd/sqldb/sqlc/migrations/000005_migration_tracker.up.sql
Andras Banki-Horvath 9acd06d296
sqldb: add table to track custom SQL migrations
This commit adds the migration_tracker table which we'll use to track if
a custom migration has already been done.
2025-01-23 09:10:59 +01:00

17 lines
935 B
SQL

-- The migration_tracker table keeps track of migrations that have been applied
-- to the database. This table ensures that migrations are idempotent and are
-- only run once. It tracks a global database version that encompasses both
-- schema migrations handled by golang-migrate and custom in-code migrations
-- for more complex data conversions that cannot be expressed in pure SQL.
CREATE TABLE IF NOT EXISTS migration_tracker (
-- version is the global version of the migration. Note that we
-- intentionally don't set it as PRIMARY KEY as it'd auto increment on
-- SQLite and our sqlc workflow will replace it with an auto
-- incrementing SERIAL on Postgres too. UNIQUE achieves the same effect
-- without the auto increment.
version INTEGER UNIQUE NOT NULL,
-- migration_time is the timestamp at which the migration was run.
migration_time TIMESTAMP NOT NULL
);