Skip to content

Commit

Permalink
Disitnguish inferred migrations by timestamp
Browse files Browse the repository at this point in the history
When two statements are run in a transaction, we need to explicitly
insert `statement_timestamp()` into the `created_at` and `updated_at`
fields rather than relying on the table default of `current_timestamp`.

`current_timestamp` is the same for all statements in a transaction,
which causes problems when ordering statements by `created_at`.
  • Loading branch information
andrew-farries committed Jun 25, 2024
1 parent 50c34ba commit da0a31e
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions pkg/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ BEGIN
-- Someone did a schema change without pgroll, include it in the history
SELECT INTO migration_id pg_catalog.format('sql_%%s',pg_catalog.substr(pg_catalog.md5(pg_catalog.random()::text), 0, 15));
INSERT INTO %[1]s.migrations (schema, name, migration, resulting_schema, done, parent, migration_type)
INSERT INTO %[1]s.migrations (schema, name, migration, resulting_schema, done, parent, migration_type, created_at, updated_at)
VALUES (
schemaname,
migration_id,
Expand All @@ -328,7 +328,9 @@ BEGIN
%[1]s.read_schema(schemaname),
true,
%[1]s.latest_version(schemaname),
'inferred'
'inferred',
statement_timestamp(),
statement_timestamp()
);
END;
$$;
Expand Down

0 comments on commit da0a31e

Please sign in to comment.