mirror of
https://github.com/coder/coder.git
synced 2026-06-03 04:58:23 +00:00
d5296a4855
## Problem Migration 000401 introduced a hardcoded `public.` schema qualifier which broke deployments using non-public schemas (see #21493). We need to prevent this from happening again. ## Solution Adds a new `lint/migrations` Make target that validates database migrations do not hardcode the `public` schema qualifier. Migrations should rely on `search_path` instead to support deployments using non-public schemas. ## Changes - Added `scripts/check_migrations_schema.sh` - a linter script that checks for `public.` references in migration files (excluding test fixtures) - Added `lint/migrations` target to the Makefile - Added `lint/migrations` to the main `lint` target so it runs in CI ## Testing - Verified the linter **fails** on current `main` (which has the hardcoded `public.` in migration 000401) - Verified the linter **passes** after applying the fix from #21493 ```bash # On main (fails) $ make lint/migrations ERROR: Migrations must not hardcode the 'public' schema. Use unqualified table names instead. # After fix (passes) $ make lint/migrations Migration schema references OK ``` ## Depends on - #21493 must be merged first (or this PR will fail CI until it is) --------- Signed-off-by: Danny Kopping <danny@coder.com> Co-authored-by: blink-so[bot] <211532188+blink-so[bot]@users.noreply.github.com> Co-authored-by: Danny Kopping <danny@coder.com>
35 lines
3.1 KiB
SQL
35 lines
3.1 KiB
SQL
-- This is a deleted user that shares the same username and linked_id as the existing user below.
|
|
-- Any future migrations need to handle this case.
|
|
INSERT INTO users(id, email, username, hashed_password, created_at, updated_at, status, rbac_roles, deleted)
|
|
VALUES ('a0061a8e-7db7-4585-838c-3116a003dd21', 'githubuser@coder.com', 'githubuser', '\x', '2022-11-02 13:05:21.445455+02', '2022-11-02 13:05:21.445455+02', 'active', '{}', true) ON CONFLICT DO NOTHING;
|
|
INSERT INTO organization_members VALUES ('a0061a8e-7db7-4585-838c-3116a003dd21', 'bb640d07-ca8a-4869-b6bc-ae61ebb2fda1', '2022-11-02 13:05:21.447595+02', '2022-11-02 13:05:21.447595+02', '{}') ON CONFLICT DO NOTHING;
|
|
INSERT INTO user_links(user_id, login_type, linked_id, oauth_access_token)
|
|
VALUES('a0061a8e-7db7-4585-838c-3116a003dd21', 'github', '100', '');
|
|
|
|
|
|
INSERT INTO users(id, email, username, hashed_password, created_at, updated_at, status, rbac_roles, deleted)
|
|
VALUES ('fc1511ef-4fcf-4a3b-98a1-8df64160e35a', 'githubuser@coder.com', 'githubuser', '\x', '2022-11-02 13:05:21.445455+02', '2022-11-02 13:05:21.445455+02', 'active', '{}', false) ON CONFLICT DO NOTHING;
|
|
INSERT INTO organization_members VALUES ('fc1511ef-4fcf-4a3b-98a1-8df64160e35a', 'bb640d07-ca8a-4869-b6bc-ae61ebb2fda1', '2022-11-02 13:05:21.447595+02', '2022-11-02 13:05:21.447595+02', '{}') ON CONFLICT DO NOTHING;
|
|
INSERT INTO user_links(user_id, login_type, linked_id, oauth_access_token)
|
|
VALUES('fc1511ef-4fcf-4a3b-98a1-8df64160e35a', 'github', '100', '');
|
|
|
|
-- Additionally, there is no unique constraint on user_id. So also add another user_link for the same user.
|
|
-- This has happened on a production database.
|
|
INSERT INTO user_links(user_id, login_type, linked_id, oauth_access_token)
|
|
VALUES('fc1511ef-4fcf-4a3b-98a1-8df64160e35a', 'oidc', 'foo', '');
|
|
|
|
|
|
-- Lastly, make 2 other users who have the same user link.
|
|
INSERT INTO users(id, email, username, hashed_password, created_at, updated_at, status, rbac_roles, deleted)
|
|
VALUES ('580ed397-727d-4aaf-950a-51f89f556c24', 'dup_link_a@coder.com', 'dupe_a', '\x', '2022-11-02 13:05:21.445455+02', '2022-11-02 13:05:21.445455+02', 'active', '{}', false) ON CONFLICT DO NOTHING;
|
|
INSERT INTO organization_members VALUES ('580ed397-727d-4aaf-950a-51f89f556c24', 'bb640d07-ca8a-4869-b6bc-ae61ebb2fda1', '2022-11-02 13:05:21.447595+02', '2022-11-02 13:05:21.447595+02', '{}') ON CONFLICT DO NOTHING;
|
|
INSERT INTO user_links(user_id, login_type, linked_id, oauth_access_token)
|
|
VALUES('580ed397-727d-4aaf-950a-51f89f556c24', 'github', '500', '');
|
|
|
|
|
|
INSERT INTO users(id, email, username, hashed_password, created_at, updated_at, status, rbac_roles, deleted)
|
|
VALUES ('c813366b-2fde-45ae-920c-101c3ad6a1e1', 'dup_link_b@coder.com', 'dupe_b', '\x', '2022-11-02 13:05:21.445455+02', '2022-11-02 13:05:21.445455+02', 'active', '{}', false) ON CONFLICT DO NOTHING;
|
|
INSERT INTO organization_members VALUES ('c813366b-2fde-45ae-920c-101c3ad6a1e1', 'bb640d07-ca8a-4869-b6bc-ae61ebb2fda1', '2022-11-02 13:05:21.447595+02', '2022-11-02 13:05:21.447595+02', '{}') ON CONFLICT DO NOTHING;
|
|
INSERT INTO user_links(user_id, login_type, linked_id, oauth_access_token)
|
|
VALUES('c813366b-2fde-45ae-920c-101c3ad6a1e1', 'github', '500', '');
|