Skip to content

Commit

Permalink
Add initial schema to migrations table
Browse files Browse the repository at this point in the history
  • Loading branch information
agedemenli committed Feb 14, 2025
1 parent f078a91 commit a998546
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions pkg/state/init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,28 @@ BEGIN
END;
$$;

-- add current schemas to the migrations table as inferred migrations
INSERT INTO placeholder.migrations (schema, name, migration, resulting_schema, done, migration_type, created_at, updated_at)
SELECT
nspname,
'initial_' || nspname,
'{}'::jsonb,
placeholder.read_schema (nspname),
TRUE,
'inferred',
statement_timestamp(),
statement_timestamp()
FROM
pg_catalog.pg_namespace
WHERE
nspname NOT IN ('pg_catalog', 'pg_toast', 'pg_temp_1', 'pg_toast_temp_1', 'pg_statistic', 'pg_temp_2', 'pg_toast_temp_2', 'pg_statistic_temp', 'information_schema', 'pgroll')
AND placeholder.read_schema (nspname) -> 'tables' != '{}'::jsonb
ON CONFLICT (schema,
name)
DO UPDATE SET
resulting_schema = EXCLUDED.resulting_schema,
updated_at = EXCLUDED.updated_at;

CREATE OR REPLACE FUNCTION placeholder.raw_migration ()
RETURNS event_trigger
LANGUAGE plpgsql
Expand Down

0 comments on commit a998546

Please sign in to comment.