diff --git a/backend/services/identity-service/prisma/migrations/20251220000000_set_user_id_sequence_start/migration.sql b/backend/services/identity-service/prisma/migrations/20251220000000_set_user_id_sequence_start/migration.sql new file mode 100644 index 00000000..79361a12 --- /dev/null +++ b/backend/services/identity-service/prisma/migrations/20251220000000_set_user_id_sequence_start/migration.sql @@ -0,0 +1,21 @@ +-- Set user_id sequence to start from 10 +-- This reserves user IDs 1-9 for system accounts + +-- Check current sequence value +DO $$ +DECLARE + current_val BIGINT; +BEGIN + -- Get current sequence value + SELECT last_value INTO current_val FROM user_accounts_user_id_seq; + + -- Only reset if current value is less than 10 + IF current_val < 10 THEN + -- Set sequence to start from 10 + -- Using setval with false means next nextval() will return 10 + PERFORM setval('user_accounts_user_id_seq', 10, false); + RAISE NOTICE 'Sequence reset to start from 10'; + ELSE + RAISE NOTICE 'Sequence already at % (>= 10), no reset needed', current_val; + END IF; +END $$;