/*
sql code defining migration schema from basic registry_schema.sql to postgresql registry.

This file is meant to be run after registry_schema.sql,
    so it doesn't include the full schema definition.

Things in this file:
    - migrations needed due to syntax differences:
        e.g. replace INTEGER PRIMARY KEY with GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY.
    - drop user_id=0, username='__self__' entry from users table,
        because we always require username when interacting with postgres database.
*/

ALTER TABLE users
    ALTER COLUMN user_id ADD GENERATED BY DEFAULT AS IDENTITY;
-- DELETE FROM users WHERE user_id=0;
-- ^this would be good eventually, but currently it also deletes source 0 due to creator_user_id cascade...

ALTER TABLE sources
    ALTER COLUMN source_id ADD GENERATED BY DEFAULT AS IDENTITY;

ALTER TABLE runs
    ALTER COLUMN run_id ADD GENERATED BY DEFAULT AS IDENTITY;

ALTER TABLE params
    ALTER COLUMN param_id ADD GENERATED BY DEFAULT AS IDENTITY;

ALTER TABLE metrics
    ALTER COLUMN metric_id ADD GENERATED BY DEFAULT AS IDENTITY;

ALTER TABLE register_history
    ALTER COLUMN history_id ADD GENERATED BY DEFAULT AS IDENTITY;

