diff --git a/coderd/database/dump.sql b/coderd/database/dump.sql index f4200f7ea3..9d79ae7c34 100644 --- a/coderd/database/dump.sql +++ b/coderd/database/dump.sql @@ -153,7 +153,7 @@ CREATE TYPE user_status AS ENUM ( 'dormant' ); -COMMENT ON TYPE user_status IS 'Defines the user status: active, dormant, or suspended.'; +COMMENT ON TYPE user_status IS 'Defines the users status: active, dormant, or suspended.'; CREATE TYPE workspace_agent_lifecycle_state AS ENUM ( 'created', diff --git a/coderd/database/migrations/000030_template_version_created_by.up.sql b/coderd/database/migrations/000030_template_version_created_by.up.sql index 36cdff6f88..00bd00650c 100644 --- a/coderd/database/migrations/000030_template_version_created_by.up.sql +++ b/coderd/database/migrations/000030_template_version_created_by.up.sql @@ -1,4 +1,3 @@ -BEGIN; ALTER TABLE ONLY template_versions ADD COLUMN IF NOT EXISTS created_by uuid REFERENCES users (id) ON DELETE RESTRICT; @@ -12,5 +11,3 @@ SET ) WHERE created_by IS NULL; - -COMMIT; diff --git a/coderd/database/migrations/000035_linked_user_id.down.sql b/coderd/database/migrations/000035_linked_user_id.down.sql index 4b75aad6ab..b1b6066854 100644 --- a/coderd/database/migrations/000035_linked_user_id.down.sql +++ b/coderd/database/migrations/000035_linked_user_id.down.sql @@ -2,8 +2,6 @@ -- the oauth_access_token, oauth_refresh_token, and oauth_expiry -- columns of api_key rows with the values from the dropped user_links -- table. -BEGIN; - DROP TABLE IF EXISTS user_links; ALTER TABLE @@ -19,5 +17,3 @@ ALTER TABLE ADD COLUMN oauth_expiry timestamp with time zone DEFAULT '0001-01-01 00:00:00+00'::timestamp with time zone NOT NULL; ALTER TABLE users DROP COLUMN login_type; - -COMMIT; diff --git a/coderd/database/migrations/000035_linked_user_id.up.sql b/coderd/database/migrations/000035_linked_user_id.up.sql index d86d577116..aa68a8e855 100644 --- a/coderd/database/migrations/000035_linked_user_id.up.sql +++ b/coderd/database/migrations/000035_linked_user_id.up.sql @@ -1,5 +1,3 @@ -BEGIN; - CREATE TABLE IF NOT EXISTS user_links ( user_id uuid NOT NULL, login_type login_type NOT NULL, @@ -70,5 +68,3 @@ FROM user_links WHERE user_links.user_id = users.id; - -COMMIT; diff --git a/coderd/database/migrations/000057_api_key_token.up.sql b/coderd/database/migrations/000057_api_key_token.up.sql index bb03e2f709..5593baabdb 100644 --- a/coderd/database/migrations/000057_api_key_token.up.sql +++ b/coderd/database/migrations/000057_api_key_token.up.sql @@ -1 +1,20 @@ -ALTER TYPE login_type ADD VALUE IF NOT EXISTS 'token'; +CREATE TYPE new_logintype AS ENUM ( + 'password', + 'github', + 'oidc', + 'token' +); + +ALTER TABLE users + ALTER COLUMN login_type DROP DEFAULT, + ALTER COLUMN login_type TYPE new_logintype USING (login_type::text::new_logintype), + ALTER COLUMN login_type SET DEFAULT 'password'::new_logintype; + +ALTER TABLE user_links + ALTER COLUMN login_type TYPE new_logintype USING (login_type::text::new_logintype); + +ALTER TABLE api_keys + ALTER COLUMN login_type TYPE new_logintype USING (login_type::text::new_logintype); + +DROP TYPE login_type; +ALTER TYPE new_logintype RENAME TO login_type; diff --git a/coderd/database/migrations/000058_template_acl.down.sql b/coderd/database/migrations/000058_template_acl.down.sql index 6b34ddf331..5320786a6e 100644 --- a/coderd/database/migrations/000058_template_acl.down.sql +++ b/coderd/database/migrations/000058_template_acl.down.sql @@ -1,8 +1,4 @@ -BEGIN; - DROP TABLE group_members; DROP TABLE groups; ALTER TABLE templates DROP COLUMN group_acl; ALTER TABLE templates DROP COLUMN user_acl; - -COMMIT; diff --git a/coderd/database/migrations/000058_template_acl.up.sql b/coderd/database/migrations/000058_template_acl.up.sql index f87cd759f9..f60a227da6 100644 --- a/coderd/database/migrations/000058_template_acl.up.sql +++ b/coderd/database/migrations/000058_template_acl.up.sql @@ -1,5 +1,3 @@ -BEGIN; - ALTER TABLE templates ADD COLUMN user_acl jsonb NOT NULL default '{}'; ALTER TABLE templates ADD COLUMN group_acl jsonb NOT NULL default '{}'; @@ -44,5 +42,3 @@ SET WHERE templates.organization_id = organizations.id ); - -COMMIT; diff --git a/coderd/database/migrations/000059_file_id.down.sql b/coderd/database/migrations/000059_file_id.down.sql index 56dbb13eeb..99dc7a0f63 100644 --- a/coderd/database/migrations/000059_file_id.down.sql +++ b/coderd/database/migrations/000059_file_id.down.sql @@ -1,5 +1,3 @@ -BEGIN; - -- Add back the storage_source column. This must be nullable temporarily. ALTER TABLE provisioner_jobs ADD COLUMN storage_source text; @@ -30,12 +28,10 @@ AND a.hash = b.hash; -- Drop the primary key on files.id. -ALTER TABLE files DROP CONSTRAINT files_pkey; +ALTER TABLE files DROP CONSTRAINT files_pkey; -- Drop the id column. ALTER TABLE files DROP COLUMN id; -- Drop the unique constraint on hash + owner. ALTER TABLE files DROP CONSTRAINT files_hash_created_by_key; -- Set the primary key back to hash. ALTER TABLE files ADD PRIMARY KEY (hash); - -COMMIT; diff --git a/coderd/database/migrations/000059_file_id.up.sql b/coderd/database/migrations/000059_file_id.up.sql index f1b6f96edd..03da21df85 100644 --- a/coderd/database/migrations/000059_file_id.up.sql +++ b/coderd/database/migrations/000059_file_id.up.sql @@ -9,8 +9,6 @@ -- This migration also adds a 'files.id' column as the primary -- key. As a side effect the provisioner_jobs must now reference -- the files.id column since the 'hash' column is now ambiguous. -BEGIN; - -- Drop the primary key on hash. ALTER TABLE files DROP CONSTRAINT files_pkey; @@ -38,5 +36,3 @@ WHERE ALTER TABLE provisioner_jobs ALTER COLUMN file_id SET NOT NULL; -- Drop storage_source since it is no longer useful for anything. ALTER TABLE provisioner_jobs DROP COLUMN storage_source; - -COMMIT; diff --git a/coderd/database/migrations/000062_group_avatars.down.sql b/coderd/database/migrations/000062_group_avatars.down.sql index eb15f35438..1885a1e26e 100644 --- a/coderd/database/migrations/000062_group_avatars.down.sql +++ b/coderd/database/migrations/000062_group_avatars.down.sql @@ -1,5 +1 @@ -BEGIN; - ALTER TABLE groups DROP COLUMN avatar_url; - -COMMIT; diff --git a/coderd/database/migrations/000062_group_avatars.up.sql b/coderd/database/migrations/000062_group_avatars.up.sql index b7f033874b..1b8e50df66 100644 --- a/coderd/database/migrations/000062_group_avatars.up.sql +++ b/coderd/database/migrations/000062_group_avatars.up.sql @@ -1,5 +1 @@ -BEGIN; - ALTER TABLE groups ADD COLUMN avatar_url text NOT NULL DEFAULT ''; - -COMMIT; diff --git a/coderd/database/migrations/000063_resource_type_group.up.sql b/coderd/database/migrations/000063_resource_type_group.up.sql index 3234c61bb7..c129924e37 100644 --- a/coderd/database/migrations/000063_resource_type_group.up.sql +++ b/coderd/database/migrations/000063_resource_type_group.up.sql @@ -1,5 +1 @@ -BEGIN; - -ALTER TYPE resource_type ADD VALUE IF NOT EXISTS 'group'; - -COMMIT; +ALTER TYPE resource_type ADD VALUE IF NOT EXISTS 'group'; diff --git a/coderd/database/migrations/000066_app_slug.up.sql b/coderd/database/migrations/000066_app_slug.up.sql index 6f67451f27..a2fe4f7bf2 100644 --- a/coderd/database/migrations/000066_app_slug.up.sql +++ b/coderd/database/migrations/000066_app_slug.up.sql @@ -1,5 +1,3 @@ -BEGIN; - -- add "slug" column to "workspace_apps" table ALTER TABLE "workspace_apps" ADD COLUMN "slug" text DEFAULT ''; @@ -12,5 +10,3 @@ ALTER TABLE "workspace_apps" ALTER COLUMN "slug" DROP DEFAULT; -- add unique index on "slug" column ALTER TABLE "workspace_apps" ADD CONSTRAINT "workspace_apps_agent_id_slug_idx" UNIQUE ("agent_id", "slug"); - -COMMIT; diff --git a/coderd/database/migrations/000067_app_display_name.down.sql b/coderd/database/migrations/000067_app_display_name.down.sql index 1b6fe06a0e..cd75693ce0 100644 --- a/coderd/database/migrations/000067_app_display_name.down.sql +++ b/coderd/database/migrations/000067_app_display_name.down.sql @@ -1,5 +1,3 @@ -BEGIN; - -- Select all apps with an extra "row_number" column that determines the "rank" -- of the display name against other display names in the same agent. WITH row_numbers AS ( @@ -30,5 +28,3 @@ ALTER TABLE "workspace_apps" RENAME COLUMN "display_name" TO "name"; -- restore unique index on "workspace_apps" table ALTER TABLE workspace_apps ADD CONSTRAINT workspace_apps_agent_id_name_key UNIQUE ("agent_id", "name"); - -COMMIT; diff --git a/coderd/database/migrations/000067_app_display_name.up.sql b/coderd/database/migrations/000067_app_display_name.up.sql index 8d210b35a7..4c543573a2 100644 --- a/coderd/database/migrations/000067_app_display_name.up.sql +++ b/coderd/database/migrations/000067_app_display_name.up.sql @@ -1,9 +1,5 @@ -BEGIN; - -- rename column "name" to "display_name" on "workspace_apps" ALTER TABLE "workspace_apps" RENAME COLUMN "name" TO "display_name"; -- drop constraint "workspace_apps_agent_id_name_key" on "workspace_apps". ALTER TABLE ONLY workspace_apps DROP CONSTRAINT IF EXISTS workspace_apps_agent_id_name_key; - -COMMIT; diff --git a/coderd/database/migrations/000068_update_template_version_created_by.up.sql b/coderd/database/migrations/000068_update_template_version_created_by.up.sql index faeeb1bea6..704e0fc823 100644 --- a/coderd/database/migrations/000068_update_template_version_created_by.up.sql +++ b/coderd/database/migrations/000068_update_template_version_created_by.up.sql @@ -1,5 +1,3 @@ -BEGIN; - UPDATE template_versions SET @@ -14,5 +12,3 @@ WHERE created_by IS NULL; ALTER TABLE template_versions ALTER COLUMN created_by SET NOT NULL; - -COMMIT; diff --git a/coderd/database/migrations/000072_add_agent_connection_timeout_and_troubleshooting_url.down.sql b/coderd/database/migrations/000072_add_agent_connection_timeout_and_troubleshooting_url.down.sql index 7486a8688d..2fa439edb1 100644 --- a/coderd/database/migrations/000072_add_agent_connection_timeout_and_troubleshooting_url.down.sql +++ b/coderd/database/migrations/000072_add_agent_connection_timeout_and_troubleshooting_url.down.sql @@ -1,9 +1,5 @@ -BEGIN; - ALTER TABLE workspace_agents DROP COLUMN connection_timeout_seconds; ALTER TABLE workspace_agents DROP COLUMN troubleshooting_url; - -COMMIT; diff --git a/coderd/database/migrations/000072_add_agent_connection_timeout_and_troubleshooting_url.up.sql b/coderd/database/migrations/000072_add_agent_connection_timeout_and_troubleshooting_url.up.sql index 3208ef8ece..1bbe6c93d9 100644 --- a/coderd/database/migrations/000072_add_agent_connection_timeout_and_troubleshooting_url.up.sql +++ b/coderd/database/migrations/000072_add_agent_connection_timeout_and_troubleshooting_url.up.sql @@ -1,5 +1,3 @@ -BEGIN; - ALTER TABLE workspace_agents ADD COLUMN connection_timeout_seconds integer NOT NULL DEFAULT 0; @@ -9,5 +7,3 @@ ALTER TABLE workspace_agents ADD COLUMN troubleshooting_url text NOT NULL DEFAULT ''; COMMENT ON COLUMN workspace_agents.troubleshooting_url IS 'URL for troubleshooting the agent.'; - -COMMIT; diff --git a/coderd/database/migrations/000090_sqlc_upgrade_fix_nullable_values.down.sql b/coderd/database/migrations/000090_sqlc_upgrade_fix_nullable_values.down.sql index 889a43c964..f6d5d46a19 100644 --- a/coderd/database/migrations/000090_sqlc_upgrade_fix_nullable_values.down.sql +++ b/coderd/database/migrations/000090_sqlc_upgrade_fix_nullable_values.down.sql @@ -1,5 +1,3 @@ -BEGIN; ALTER TABLE parameter_schemas ALTER COLUMN default_source_scheme DROP NOT NULL; ALTER TABLE parameter_schemas ALTER COLUMN default_destination_scheme DROP NOT NULL; -COMMIT; diff --git a/coderd/database/migrations/000090_sqlc_upgrade_fix_nullable_values.up.sql b/coderd/database/migrations/000090_sqlc_upgrade_fix_nullable_values.up.sql index fbceb2ca3d..7da3466acf 100644 --- a/coderd/database/migrations/000090_sqlc_upgrade_fix_nullable_values.up.sql +++ b/coderd/database/migrations/000090_sqlc_upgrade_fix_nullable_values.up.sql @@ -1,7 +1,5 @@ -BEGIN; UPDATE parameter_schemas SET default_source_scheme = 'none' WHERE default_source_scheme IS NULL; ALTER TABLE parameter_schemas ALTER COLUMN default_source_scheme SET NOT NULL; UPDATE parameter_schemas SET default_destination_scheme = 'none' WHERE default_destination_scheme IS NULL; ALTER TABLE parameter_schemas ALTER COLUMN default_destination_scheme SET NOT NULL; -COMMIT; diff --git a/coderd/database/migrations/000093_add_workspace_agent_invert_delay_login_until_ready_to_login_before_ready.down.sql b/coderd/database/migrations/000093_add_workspace_agent_invert_delay_login_until_ready_to_login_before_ready.down.sql index 9fec239936..b071485772 100644 --- a/coderd/database/migrations/000093_add_workspace_agent_invert_delay_login_until_ready_to_login_before_ready.down.sql +++ b/coderd/database/migrations/000093_add_workspace_agent_invert_delay_login_until_ready_to_login_before_ready.down.sql @@ -1,8 +1,6 @@ -BEGIN; ALTER TABLE workspace_agents RENAME COLUMN login_before_ready TO delay_login_until_ready; ALTER TABLE workspace_agents ALTER COLUMN delay_login_until_ready SET DEFAULT false; UPDATE workspace_agents SET delay_login_until_ready = NOT delay_login_until_ready; COMMENT ON COLUMN workspace_agents.delay_login_until_ready IS 'If true, the agent will delay logins until it is ready (e.g. executing startup script has ended).'; -COMMIT; diff --git a/coderd/database/migrations/000093_add_workspace_agent_invert_delay_login_until_ready_to_login_before_ready.up.sql b/coderd/database/migrations/000093_add_workspace_agent_invert_delay_login_until_ready_to_login_before_ready.up.sql index 2f49830da4..df8a731f5d 100644 --- a/coderd/database/migrations/000093_add_workspace_agent_invert_delay_login_until_ready_to_login_before_ready.up.sql +++ b/coderd/database/migrations/000093_add_workspace_agent_invert_delay_login_until_ready_to_login_before_ready.up.sql @@ -1,8 +1,6 @@ -BEGIN; ALTER TABLE workspace_agents RENAME COLUMN delay_login_until_ready TO login_before_ready; ALTER TABLE workspace_agents ALTER COLUMN login_before_ready SET DEFAULT true; UPDATE workspace_agents SET login_before_ready = NOT login_before_ready; COMMENT ON COLUMN workspace_agents.login_before_ready IS 'If true, the agent will not prevent login before it is ready (e.g. startup script is still executing).'; -COMMIT; diff --git a/coderd/database/migrations/000096_agent_resolved_directory.down.sql b/coderd/database/migrations/000096_agent_resolved_directory.down.sql index e54c206b26..b898645020 100644 --- a/coderd/database/migrations/000096_agent_resolved_directory.down.sql +++ b/coderd/database/migrations/000096_agent_resolved_directory.down.sql @@ -1,6 +1,2 @@ -BEGIN; - ALTER TABLE ONLY workspace_agents DROP COLUMN IF EXISTS expanded_directory; - -COMMIT; diff --git a/coderd/database/migrations/000096_agent_resolved_directory.up.sql b/coderd/database/migrations/000096_agent_resolved_directory.up.sql index 94e65b051f..a97f3f1222 100644 --- a/coderd/database/migrations/000096_agent_resolved_directory.up.sql +++ b/coderd/database/migrations/000096_agent_resolved_directory.up.sql @@ -1,9 +1,5 @@ -BEGIN; - ALTER TABLE ONLY workspace_agents ADD COLUMN IF NOT EXISTS expanded_directory varchar(4096) DEFAULT '' NOT NULL; COMMENT ON COLUMN workspace_agents.expanded_directory IS 'The resolved path of a user-specified directory. e.g. ~/coder -> /home/coder/coder'; - -COMMIT; diff --git a/coderd/database/migrations/000097_license_not_null_uuid.up.sql b/coderd/database/migrations/000097_license_not_null_uuid.up.sql index ca64a6850b..31c9f4f7bd 100644 --- a/coderd/database/migrations/000097_license_not_null_uuid.up.sql +++ b/coderd/database/migrations/000097_license_not_null_uuid.up.sql @@ -1,8 +1,4 @@ -BEGIN; - -- We need to assign uuids to any existing licenses that don't have them. UPDATE licenses SET uuid = gen_random_uuid() WHERE uuid IS NULL; -- Assert no licenses have null uuids. ALTER TABLE ONLY licenses ALTER COLUMN uuid SET NOT NULL; - -COMMIT; diff --git a/coderd/database/migrations/000103_add_apikey_name.down.sql b/coderd/database/migrations/000103_add_apikey_name.down.sql index f7070bd363..e1b50394d1 100644 --- a/coderd/database/migrations/000103_add_apikey_name.down.sql +++ b/coderd/database/migrations/000103_add_apikey_name.down.sql @@ -1,8 +1,4 @@ -BEGIN; - DROP INDEX idx_api_key_name; ALTER TABLE ONLY api_keys DROP COLUMN IF EXISTS token_name; - -COMMIT; diff --git a/coderd/database/migrations/000103_add_apikey_name.up.sql b/coderd/database/migrations/000103_add_apikey_name.up.sql index f1ba24ae09..b9b60c89a0 100644 --- a/coderd/database/migrations/000103_add_apikey_name.up.sql +++ b/coderd/database/migrations/000103_add_apikey_name.up.sql @@ -1,5 +1,3 @@ -BEGIN; - ALTER TABLE ONLY api_keys ADD COLUMN IF NOT EXISTS token_name text NOT NULL DEFAULT ''; @@ -13,5 +11,3 @@ WHERE CREATE UNIQUE INDEX idx_api_key_name ON api_keys USING btree (user_id, token_name) WHERE (login_type = 'token'); - -COMMIT; diff --git a/coderd/database/migrations/000110_add_startup_logs.up.sql b/coderd/database/migrations/000110_add_startup_logs.up.sql index f74c014dd5..847358c405 100644 --- a/coderd/database/migrations/000110_add_startup_logs.up.sql +++ b/coderd/database/migrations/000110_add_startup_logs.up.sql @@ -1,5 +1,3 @@ -BEGIN; - CREATE TABLE IF NOT EXISTS workspace_agent_startup_logs ( agent_id uuid NOT NULL REFERENCES workspace_agents (id) ON DELETE CASCADE, created_at timestamptz NOT NULL, @@ -14,5 +12,3 @@ ALTER TABLE workspace_agents ADD COLUMN startup_logs_overflowed boolean NOT NULL COMMENT ON COLUMN workspace_agents.startup_logs_length IS 'Total length of startup logs'; COMMENT ON COLUMN workspace_agents.startup_logs_overflowed IS 'Whether the startup logs overflowed in length'; - -COMMIT; diff --git a/coderd/database/migrations/000114_workspace_proxy.down.sql b/coderd/database/migrations/000114_workspace_proxy.down.sql index 8d428817f4..5c289e5770 100644 --- a/coderd/database/migrations/000114_workspace_proxy.down.sql +++ b/coderd/database/migrations/000114_workspace_proxy.down.sql @@ -1,4 +1 @@ -BEGIN; DROP TABLE workspace_proxies; - -COMMIT; diff --git a/coderd/database/migrations/000114_workspace_proxy.up.sql b/coderd/database/migrations/000114_workspace_proxy.up.sql index 5030a5da79..33c22f7661 100644 --- a/coderd/database/migrations/000114_workspace_proxy.up.sql +++ b/coderd/database/migrations/000114_workspace_proxy.up.sql @@ -1,4 +1,3 @@ -BEGIN; CREATE TABLE workspace_proxies ( id uuid NOT NULL, name text NOT NULL, @@ -19,5 +18,3 @@ COMMENT ON COLUMN workspace_proxies.wildcard_hostname IS 'Hostname with the wild -- Enforces no active proxies have the same name. CREATE UNIQUE INDEX ON workspace_proxies (name) WHERE deleted = FALSE; - -COMMIT; diff --git a/coderd/database/migrations/000118_workspace_proxy_token.down.sql b/coderd/database/migrations/000118_workspace_proxy_token.down.sql index eb698ce6e3..47914a5afd 100644 --- a/coderd/database/migrations/000118_workspace_proxy_token.down.sql +++ b/coderd/database/migrations/000118_workspace_proxy_token.down.sql @@ -1,6 +1,2 @@ -BEGIN; - ALTER TABLE workspace_proxies DROP COLUMN token_hashed_secret; - -COMMIT; diff --git a/coderd/database/migrations/000118_workspace_proxy_token.up.sql b/coderd/database/migrations/000118_workspace_proxy_token.up.sql index f4f1a66c23..b514a4a41b 100644 --- a/coderd/database/migrations/000118_workspace_proxy_token.up.sql +++ b/coderd/database/migrations/000118_workspace_proxy_token.up.sql @@ -1,5 +1,3 @@ -BEGIN; - -- It's difficult to generate tokens for existing proxies, so we'll just delete -- them if they exist. -- @@ -18,5 +16,3 @@ COMMENT ON COLUMN workspace_proxies.deleted COMMENT ON COLUMN workspace_proxies.icon IS 'Expects an emoji character. (/emojis/1f1fa-1f1f8.png)'; - -COMMIT; diff --git a/coderd/database/migrations/000119_workspace_proxy_name_idx.down.sql b/coderd/database/migrations/000119_workspace_proxy_name_idx.down.sql index 3311a6cd7c..9f5b4f1829 100644 --- a/coderd/database/migrations/000119_workspace_proxy_name_idx.down.sql +++ b/coderd/database/migrations/000119_workspace_proxy_name_idx.down.sql @@ -1,8 +1,4 @@ -BEGIN; - DROP INDEX IF EXISTS workspace_proxies_lower_name_idx; -- Enforces no active proxies have the same name. CREATE UNIQUE INDEX ON workspace_proxies (name) WHERE deleted = FALSE; - -COMMIT; diff --git a/coderd/database/migrations/000119_workspace_proxy_name_idx.up.sql b/coderd/database/migrations/000119_workspace_proxy_name_idx.up.sql index 0101905491..bc227d68d2 100644 --- a/coderd/database/migrations/000119_workspace_proxy_name_idx.up.sql +++ b/coderd/database/migrations/000119_workspace_proxy_name_idx.up.sql @@ -1,5 +1,3 @@ -BEGIN; - -- No one is using this feature yet as of writing this migration, so this is -- fine. Just delete all workspace proxies to prevent the new index from having -- conflicts. @@ -7,5 +5,3 @@ DELETE FROM workspace_proxies; DROP INDEX IF EXISTS workspace_proxies_name_idx; CREATE UNIQUE INDEX workspace_proxies_lower_name_idx ON workspace_proxies USING btree (lower(name)) WHERE deleted = FALSE; - -COMMIT; diff --git a/coderd/database/migrations/000120_trigger_delete_user_apikey.down.sql b/coderd/database/migrations/000120_trigger_delete_user_apikey.down.sql index f5c8592c44..66178aa1e2 100644 --- a/coderd/database/migrations/000120_trigger_delete_user_apikey.down.sql +++ b/coderd/database/migrations/000120_trigger_delete_user_apikey.down.sql @@ -1,9 +1,5 @@ -BEGIN; - DROP TRIGGER IF EXISTS trigger_update_users ON users; DROP FUNCTION IF EXISTS delete_deleted_user_api_keys; DROP TRIGGER IF EXISTS trigger_insert_apikeys ON api_keys; DROP FUNCTION IF EXISTS insert_apikey_fail_if_user_deleted; - -COMMIT; diff --git a/coderd/database/migrations/000120_trigger_delete_user_apikey.up.sql b/coderd/database/migrations/000120_trigger_delete_user_apikey.up.sql index 9ea208bef4..4d2536f929 100644 --- a/coderd/database/migrations/000120_trigger_delete_user_apikey.up.sql +++ b/coderd/database/migrations/000120_trigger_delete_user_apikey.up.sql @@ -1,5 +1,3 @@ -BEGIN; - -- We need to delete all existing API keys for soft-deleted users. DELETE FROM api_keys @@ -51,5 +49,3 @@ CREATE TRIGGER trigger_insert_apikeys BEFORE INSERT ON api_keys FOR EACH ROW EXECUTE PROCEDURE insert_apikey_fail_if_user_deleted(); - -COMMIT; diff --git a/coderd/database/migrations/000122_add_template_cleanup_ttls.down.sql b/coderd/database/migrations/000122_add_template_cleanup_ttls.down.sql index 78a04e961e..70fd50d21a 100644 --- a/coderd/database/migrations/000122_add_template_cleanup_ttls.down.sql +++ b/coderd/database/migrations/000122_add_template_cleanup_ttls.down.sql @@ -1,4 +1,2 @@ -BEGIN; ALTER TABLE ONLY templates DROP COLUMN IF EXISTS failure_ttl; ALTER TABLE ONLY templates DROP COLUMN IF EXISTS inactivity_ttl; -COMMIT; diff --git a/coderd/database/migrations/000122_add_template_cleanup_ttls.up.sql b/coderd/database/migrations/000122_add_template_cleanup_ttls.up.sql index f043356375..980588e269 100644 --- a/coderd/database/migrations/000122_add_template_cleanup_ttls.up.sql +++ b/coderd/database/migrations/000122_add_template_cleanup_ttls.up.sql @@ -1,4 +1,2 @@ -BEGIN; ALTER TABLE ONLY templates ADD COLUMN IF NOT EXISTS failure_ttl BIGINT NOT NULL DEFAULT 0; ALTER TABLE ONLY templates ADD COLUMN IF NOT EXISTS inactivity_ttl BIGINT NOT NULL DEFAULT 0; -COMMIT; diff --git a/coderd/database/migrations/000123_workspace_agent_subsystem.down.sql b/coderd/database/migrations/000123_workspace_agent_subsystem.down.sql index ec1fc4aa26..9bd39b0034 100644 --- a/coderd/database/migrations/000123_workspace_agent_subsystem.down.sql +++ b/coderd/database/migrations/000123_workspace_agent_subsystem.down.sql @@ -1,4 +1,2 @@ -BEGIN; ALTER TABLE workspace_agents DROP COLUMN subsystem; DROP TYPE workspace_agent_subsystem; -COMMIT; diff --git a/coderd/database/migrations/000123_workspace_agent_subsystem.up.sql b/coderd/database/migrations/000123_workspace_agent_subsystem.up.sql index 747c5d362f..35d4389bec 100644 --- a/coderd/database/migrations/000123_workspace_agent_subsystem.up.sql +++ b/coderd/database/migrations/000123_workspace_agent_subsystem.up.sql @@ -1,4 +1,2 @@ -BEGIN; CREATE TYPE workspace_agent_subsystem AS ENUM ('envbuilder', 'envbox', 'none'); ALTER TABLE workspace_agents ADD COLUMN subsystem workspace_agent_subsystem NOT NULL default 'none'; -COMMIT; diff --git a/coderd/database/migrations/000124_validation_min_max_nullable.down.sql b/coderd/database/migrations/000124_validation_min_max_nullable.down.sql index 39a8eb69a3..3345d22dc1 100644 --- a/coderd/database/migrations/000124_validation_min_max_nullable.down.sql +++ b/coderd/database/migrations/000124_validation_min_max_nullable.down.sql @@ -1,6 +1,4 @@ -BEGIN; UPDATE template_version_parameters SET validation_min = 0 WHERE validation_min = NULL; UPDATE template_version_parameters SET validation_max = 0 WHERE validation_max = NULL; ALTER TABLE template_version_parameters ALTER COLUMN validation_min SET NOT NULL; ALTER TABLE template_version_parameters ALTER COLUMN validation_max SET NOT NULL; -COMMIT; diff --git a/coderd/database/migrations/000124_validation_min_max_nullable.up.sql b/coderd/database/migrations/000124_validation_min_max_nullable.up.sql index ea3160747e..be91df47c1 100644 --- a/coderd/database/migrations/000124_validation_min_max_nullable.up.sql +++ b/coderd/database/migrations/000124_validation_min_max_nullable.up.sql @@ -1,6 +1,4 @@ -BEGIN; ALTER TABLE template_version_parameters ALTER COLUMN validation_min DROP NOT NULL; ALTER TABLE template_version_parameters ALTER COLUMN validation_max DROP NOT NULL; UPDATE template_version_parameters SET validation_min = NULL WHERE validation_min = 0; UPDATE template_version_parameters SET validation_max = NULL WHERE validation_max = 0; -COMMIT; diff --git a/coderd/database/migrations/000125_rename_login_before_ready_to_startup_script_behavior.down.sql b/coderd/database/migrations/000125_rename_login_before_ready_to_startup_script_behavior.down.sql index 3c93e6e92b..755fb52c7f 100644 --- a/coderd/database/migrations/000125_rename_login_before_ready_to_startup_script_behavior.down.sql +++ b/coderd/database/migrations/000125_rename_login_before_ready_to_startup_script_behavior.down.sql @@ -1,5 +1,3 @@ -BEGIN; - ALTER TABLE workspace_agents ADD COLUMN login_before_ready boolean NOT NULL DEFAULT TRUE; UPDATE workspace_agents SET login_before_ready = CASE WHEN startup_script_behavior = 'non-blocking' THEN TRUE ELSE FALSE END; @@ -8,5 +6,3 @@ ALTER TABLE workspace_agents DROP COLUMN startup_script_behavior; DROP TYPE startup_script_behavior; COMMENT ON COLUMN workspace_agents.login_before_ready IS 'If true, the agent will delay logins until it is ready (e.g. executing startup script has ended).'; - -COMMIT; diff --git a/coderd/database/migrations/000125_rename_login_before_ready_to_startup_script_behavior.up.sql b/coderd/database/migrations/000125_rename_login_before_ready_to_startup_script_behavior.up.sql index 408cd854de..1091c9711e 100644 --- a/coderd/database/migrations/000125_rename_login_before_ready_to_startup_script_behavior.up.sql +++ b/coderd/database/migrations/000125_rename_login_before_ready_to_startup_script_behavior.up.sql @@ -1,5 +1,3 @@ -BEGIN; - CREATE TYPE startup_script_behavior AS ENUM ('blocking', 'non-blocking'); ALTER TABLE workspace_agents ADD COLUMN startup_script_behavior startup_script_behavior NOT NULL DEFAULT 'non-blocking'; @@ -8,5 +6,3 @@ UPDATE workspace_agents SET startup_script_behavior = (CASE WHEN login_before_re ALTER TABLE workspace_agents DROP COLUMN login_before_ready; COMMENT ON COLUMN workspace_agents.startup_script_behavior IS 'When startup script behavior is non-blocking, the workspace will be ready and accessible upon agent connection, when it is blocking, workspace will wait for the startup script to complete before becoming ready and accessible.'; - -COMMIT; diff --git a/coderd/database/migrations/000128_template_locked_ttl.down.sql b/coderd/database/migrations/000128_template_locked_ttl.down.sql index 71beb28ebe..72b2ae64d4 100644 --- a/coderd/database/migrations/000128_template_locked_ttl.down.sql +++ b/coderd/database/migrations/000128_template_locked_ttl.down.sql @@ -1,3 +1 @@ -BEGIN; ALTER TABLE templates DROP COLUMN locked_ttl; -COMMIT; diff --git a/coderd/database/migrations/000128_template_locked_ttl.up.sql b/coderd/database/migrations/000128_template_locked_ttl.up.sql index 0f51a424fe..24d53033cf 100644 --- a/coderd/database/migrations/000128_template_locked_ttl.up.sql +++ b/coderd/database/migrations/000128_template_locked_ttl.up.sql @@ -1,3 +1 @@ -BEGIN; ALTER TABLE templates ADD COLUMN locked_ttl BIGINT NOT NULL DEFAULT 0; -COMMIT; diff --git a/coderd/database/migrations/000129_drop_startup_logs_eof_and_add_completion.down.sql b/coderd/database/migrations/000129_drop_startup_logs_eof_and_add_completion.down.sql index 9d57ded80b..9f2c4878ec 100644 --- a/coderd/database/migrations/000129_drop_startup_logs_eof_and_add_completion.down.sql +++ b/coderd/database/migrations/000129_drop_startup_logs_eof_and_add_completion.down.sql @@ -1,5 +1,3 @@ -BEGIN; - ALTER TABLE workspace_agents DROP COLUMN started_at, DROP COLUMN ready_at; @@ -9,5 +7,3 @@ ALTER TABLE workspace_agents ALTER TABLE workspace_agent_startup_logs ADD COLUMN eof boolean NOT NULL DEFAULT false; COMMENT ON COLUMN workspace_agent_startup_logs.eof IS 'End of file reached'; - -COMMIT; diff --git a/coderd/database/migrations/000129_drop_startup_logs_eof_and_add_completion.up.sql b/coderd/database/migrations/000129_drop_startup_logs_eof_and_add_completion.up.sql index 7a11298c83..7d521be4af 100644 --- a/coderd/database/migrations/000129_drop_startup_logs_eof_and_add_completion.up.sql +++ b/coderd/database/migrations/000129_drop_startup_logs_eof_and_add_completion.up.sql @@ -1,5 +1,3 @@ -BEGIN; - DELETE FROM workspace_agent_startup_logs WHERE eof IS TRUE; ALTER TABLE workspace_agent_startup_logs DROP COLUMN eof; @@ -10,5 +8,3 @@ ALTER TABLE workspace_agents COMMENT ON COLUMN workspace_agents.started_at IS 'The time the agent entered the starting lifecycle state'; COMMENT ON COLUMN workspace_agents.ready_at IS 'The time the agent entered the ready or start_error lifecycle state'; - -COMMIT; diff --git a/coderd/database/migrations/000130_ha_coordinator.down.sql b/coderd/database/migrations/000130_ha_coordinator.down.sql index 54c8b02539..a1e4633600 100644 --- a/coderd/database/migrations/000130_ha_coordinator.down.sql +++ b/coderd/database/migrations/000130_ha_coordinator.down.sql @@ -1,5 +1,3 @@ -BEGIN; - DROP TRIGGER IF EXISTS tailnet_notify_client_change ON tailnet_clients; DROP FUNCTION IF EXISTS tailnet_notify_client_change; DROP INDEX IF EXISTS idx_tailnet_clients_agent; @@ -14,5 +12,3 @@ DROP TABLE IF EXISTS tailnet_agents; DROP TRIGGER IF EXISTS tailnet_notify_coordinator_heartbeat ON tailnet_coordinators; DROP FUNCTION IF EXISTS tailnet_notify_coordinator_heartbeat; DROP TABLE IF EXISTS tailnet_coordinators; - -COMMIT; diff --git a/coderd/database/migrations/000130_ha_coordinator.up.sql b/coderd/database/migrations/000130_ha_coordinator.up.sql index f30bd077c7..b444520e82 100644 --- a/coderd/database/migrations/000130_ha_coordinator.up.sql +++ b/coderd/database/migrations/000130_ha_coordinator.up.sql @@ -1,5 +1,3 @@ -BEGIN; - CREATE TABLE tailnet_coordinators ( id uuid NOT NULL PRIMARY KEY, heartbeat_at timestamp with time zone NOT NULL @@ -93,5 +91,3 @@ CREATE TRIGGER tailnet_notify_coordinator_heartbeat AFTER INSERT OR UPDATE ON tailnet_coordinators FOR EACH ROW EXECUTE PROCEDURE tailnet_notify_coordinator_heartbeat(); - -COMMIT; diff --git a/coderd/database/migrations/000131_workspace_locked.down.sql b/coderd/database/migrations/000131_workspace_locked.down.sql index d622787938..78361c7e9e 100644 --- a/coderd/database/migrations/000131_workspace_locked.down.sql +++ b/coderd/database/migrations/000131_workspace_locked.down.sql @@ -1,3 +1 @@ -BEGIN; ALTER TABLE workspaces DROP COLUMN locked_at; -COMMIT; diff --git a/coderd/database/migrations/000131_workspace_locked.up.sql b/coderd/database/migrations/000131_workspace_locked.up.sql index e62a6a351d..945180df5d 100644 --- a/coderd/database/migrations/000131_workspace_locked.up.sql +++ b/coderd/database/migrations/000131_workspace_locked.up.sql @@ -1,3 +1 @@ -BEGIN; ALTER TABLE workspaces ADD COLUMN locked_at timestamptz NULL; -COMMIT; diff --git a/coderd/database/migrations/000134_workspace_build_reason.up.sql b/coderd/database/migrations/000134_workspace_build_reason.up.sql index ae9d30fae9..80914cfa2a 100644 --- a/coderd/database/migrations/000134_workspace_build_reason.up.sql +++ b/coderd/database/migrations/000134_workspace_build_reason.up.sql @@ -1,5 +1,3 @@ -BEGIN; ALTER TYPE build_reason ADD VALUE IF NOT EXISTS 'autolock'; ALTER TYPE build_reason ADD VALUE IF NOT EXISTS 'failedstop'; ALTER TYPE build_reason ADD VALUE IF NOT EXISTS 'autodelete'; -COMMIT; diff --git a/coderd/database/migrations/000138_join_users.down.sql b/coderd/database/migrations/000138_join_users.down.sql index 754574f7b5..b70115d3d6 100644 --- a/coderd/database/migrations/000138_join_users.down.sql +++ b/coderd/database/migrations/000138_join_users.down.sql @@ -1,6 +1,2 @@ -BEGIN; - DROP VIEW template_with_users; DROP VIEW visible_users; - -COMMIT; diff --git a/coderd/database/migrations/000138_join_users.up.sql b/coderd/database/migrations/000138_join_users.up.sql index 198dd55edf..ed4312140c 100644 --- a/coderd/database/migrations/000138_join_users.up.sql +++ b/coderd/database/migrations/000138_join_users.up.sql @@ -1,5 +1,3 @@ -BEGIN; - CREATE VIEW visible_users AS @@ -26,5 +24,3 @@ AS templates.created_by = visible_users.id; COMMENT ON VIEW template_with_users IS 'Joins in the username + avatar url of the created by user.'; - -COMMIT; diff --git a/coderd/database/migrations/000139_template_restart_requirement.down.sql b/coderd/database/migrations/000139_template_restart_requirement.down.sql index f882ada1fd..bd2bddf517 100644 --- a/coderd/database/migrations/000139_template_restart_requirement.down.sql +++ b/coderd/database/migrations/000139_template_restart_requirement.down.sql @@ -1,5 +1,3 @@ -BEGIN; - -- Delete the new version of the template_with_users view to remove the column -- dependency. DROP VIEW template_with_users; @@ -25,5 +23,3 @@ AS ON templates.created_by = visible_users.id; COMMENT ON VIEW template_with_users IS 'Joins in the username + avatar url of the created by user.'; - -COMMIT; diff --git a/coderd/database/migrations/000139_template_restart_requirement.up.sql b/coderd/database/migrations/000139_template_restart_requirement.up.sql index ec8f2f520a..7cfc3dafe8 100644 --- a/coderd/database/migrations/000139_template_restart_requirement.up.sql +++ b/coderd/database/migrations/000139_template_restart_requirement.up.sql @@ -1,5 +1,3 @@ -BEGIN; - ALTER TABLE templates -- The max_ttl column will be dropped eventually when the new "restart -- requirement" feature flag is fully rolled out. @@ -31,5 +29,3 @@ AS ON templates.created_by = visible_users.id; COMMENT ON VIEW template_with_users IS 'Joins in the username + avatar url of the created by user.'; - -COMMIT; diff --git a/coderd/database/migrations/000141_join_users_build_version.down.sql b/coderd/database/migrations/000141_join_users_build_version.down.sql index 0c27698e8c..2eb57c5a97 100644 --- a/coderd/database/migrations/000141_join_users_build_version.down.sql +++ b/coderd/database/migrations/000141_join_users_build_version.down.sql @@ -1,6 +1,2 @@ -BEGIN; - DROP VIEW workspace_build_with_user; DROP VIEW template_version_with_user; - -COMMIT; diff --git a/coderd/database/migrations/000141_join_users_build_version.up.sql b/coderd/database/migrations/000141_join_users_build_version.up.sql index eed74c09b0..1e865c0ffa 100644 --- a/coderd/database/migrations/000141_join_users_build_version.up.sql +++ b/coderd/database/migrations/000141_join_users_build_version.up.sql @@ -1,5 +1,3 @@ -BEGIN; - -- If you need to update this view, put 'DROP VIEW workspace_build_with_user;' before this. CREATE VIEW workspace_build_with_user @@ -34,5 +32,3 @@ FROM template_versions.created_by = visible_users.id; COMMENT ON VIEW template_version_with_user IS 'Joins in the username + avatar url of the created by user.'; - -COMMIT; diff --git a/coderd/database/migrations/000142_proxy_derp.down.sql b/coderd/database/migrations/000142_proxy_derp.down.sql index 9937e47591..c7d48617c5 100644 --- a/coderd/database/migrations/000142_proxy_derp.down.sql +++ b/coderd/database/migrations/000142_proxy_derp.down.sql @@ -1,5 +1,3 @@ -BEGIN; - -- drop any rows that aren't primary replicas DELETE FROM replicas WHERE "primary" = false; @@ -11,5 +9,3 @@ ALTER TABLE workspace_proxies DROP CONSTRAINT workspace_proxies_region_id_unique, DROP COLUMN region_id, DROP COLUMN derp_enabled; - -COMMIT; diff --git a/coderd/database/migrations/000142_proxy_derp.up.sql b/coderd/database/migrations/000142_proxy_derp.up.sql index e214fe50fc..fa9598c790 100644 --- a/coderd/database/migrations/000142_proxy_derp.up.sql +++ b/coderd/database/migrations/000142_proxy_derp.up.sql @@ -1,5 +1,3 @@ -BEGIN; - ALTER TABLE replicas ADD COLUMN "primary" boolean NOT NULL DEFAULT true; @@ -9,5 +7,3 @@ ALTER TABLE workspace_proxies ADD COLUMN region_id serial NOT NULL, ADD COLUMN derp_enabled boolean NOT NULL DEFAULT true, ADD CONSTRAINT workspace_proxies_region_id_unique UNIQUE (region_id); - -COMMIT; diff --git a/coderd/database/migrations/000143_workspace_agent_logs.down.sql b/coderd/database/migrations/000143_workspace_agent_logs.down.sql index 53b0d03f44..5fe6e3b8e6 100644 --- a/coderd/database/migrations/000143_workspace_agent_logs.down.sql +++ b/coderd/database/migrations/000143_workspace_agent_logs.down.sql @@ -1,8 +1,6 @@ -BEGIN; ALTER TABLE workspace_agent_logs RENAME TO workspace_agent_startup_logs; ALTER TABLE workspace_agent_startup_logs DROP COLUMN source; DROP TYPE workspace_agent_log_source; ALTER TABLE workspace_agents RENAME COLUMN logs_overflowed TO startup_logs_overflowed; ALTER TABLE workspace_agents RENAME COLUMN logs_length TO startup_logs_length; ALTER TABLE workspace_agents RENAME CONSTRAINT max_logs_length TO max_startup_logs_length; -COMMIT; diff --git a/coderd/database/migrations/000143_workspace_agent_logs.up.sql b/coderd/database/migrations/000143_workspace_agent_logs.up.sql index 7de9cf07aa..079d5e42e9 100644 --- a/coderd/database/migrations/000143_workspace_agent_logs.up.sql +++ b/coderd/database/migrations/000143_workspace_agent_logs.up.sql @@ -1,8 +1,6 @@ -BEGIN; CREATE TYPE workspace_agent_log_source AS ENUM ('startup_script', 'shutdown_script', 'kubernetes_logs', 'envbox', 'envbuilder', 'external'); ALTER TABLE workspace_agent_startup_logs RENAME TO workspace_agent_logs; ALTER TABLE workspace_agent_logs ADD COLUMN source workspace_agent_log_source NOT NULL DEFAULT 'startup_script'; ALTER TABLE workspace_agents RENAME COLUMN startup_logs_overflowed TO logs_overflowed; ALTER TABLE workspace_agents RENAME COLUMN startup_logs_length TO logs_length; ALTER TABLE workspace_agents RENAME CONSTRAINT max_startup_logs_length TO max_logs_length; -COMMIT; diff --git a/coderd/database/migrations/000144_user_status_dormant.down.sql b/coderd/database/migrations/000144_user_status_dormant.down.sql index 55504e0938..12af994090 100644 --- a/coderd/database/migrations/000144_user_status_dormant.down.sql +++ b/coderd/database/migrations/000144_user_status_dormant.down.sql @@ -1,3 +1,3 @@ -- It's not possible to drop enum values from enum types, so the UP has "IF NOT EXISTS" -UPDATE users SET status = 'active'::user_status WHERE status = 'dormant'::user_status; +UPDATE users SET status = 'active'::user_status WHERE status::text = 'dormant'; diff --git a/coderd/database/migrations/000144_user_status_dormant.up.sql b/coderd/database/migrations/000144_user_status_dormant.up.sql index 106cc10b53..abad786d37 100644 --- a/coderd/database/migrations/000144_user_status_dormant.up.sql +++ b/coderd/database/migrations/000144_user_status_dormant.up.sql @@ -1,2 +1,14 @@ -ALTER TYPE user_status ADD VALUE IF NOT EXISTS 'dormant'; -COMMENT ON TYPE user_status IS 'Defines the user status: active, dormant, or suspended.'; +CREATE TYPE new_user_status AS ENUM ( + 'active', + 'suspended', + 'dormant' +); +COMMENT ON TYPE new_user_status IS 'Defines the users status: active, dormant, or suspended.'; + +ALTER TABLE users + ALTER COLUMN status DROP DEFAULT, + ALTER COLUMN status TYPE new_user_status USING (status::text::new_user_status), + ALTER COLUMN status SET DEFAULT 'active'::new_user_status; + +DROP TYPE user_status; +ALTER TYPE new_user_status RENAME TO user_status; diff --git a/coderd/database/migrations/000146_proxy_derp_only.up.sql b/coderd/database/migrations/000146_proxy_derp_only.up.sql index d63c602f78..fb46ca00f0 100644 --- a/coderd/database/migrations/000146_proxy_derp_only.up.sql +++ b/coderd/database/migrations/000146_proxy_derp_only.up.sql @@ -1,8 +1,4 @@ -BEGIN; - ALTER TABLE workspace_proxies ADD COLUMN "derp_only" BOOLEAN NOT NULL DEFAULT false; COMMENT ON COLUMN workspace_proxies.derp_only IS 'Disables app/terminal proxying for this proxy and only acts as a DERP relay.'; - -COMMIT; diff --git a/coderd/database/migrations/000147_group_display_name.down.sql b/coderd/database/migrations/000147_group_display_name.down.sql index b04850449f..7e9af6c21c 100644 --- a/coderd/database/migrations/000147_group_display_name.down.sql +++ b/coderd/database/migrations/000147_group_display_name.down.sql @@ -1,6 +1,2 @@ -BEGIN; - ALTER TABLE groups DROP COLUMN display_name; - -COMMIT; diff --git a/coderd/database/migrations/000147_group_display_name.up.sql b/coderd/database/migrations/000147_group_display_name.up.sql index a812ad8aa3..a7448ffb23 100644 --- a/coderd/database/migrations/000147_group_display_name.up.sql +++ b/coderd/database/migrations/000147_group_display_name.up.sql @@ -1,8 +1,4 @@ -BEGIN; - ALTER TABLE groups ADD COLUMN display_name TEXT NOT NULL DEFAULT ''; COMMENT ON COLUMN groups.display_name IS 'Display name is a custom, human-friendly group name that user can set. This is not required to be unique and can be the empty string.'; - -COMMIT; diff --git a/coderd/database/migrations/000148_group_source.down.sql b/coderd/database/migrations/000148_group_source.down.sql index 504c227d18..1bfef7ea49 100644 --- a/coderd/database/migrations/000148_group_source.down.sql +++ b/coderd/database/migrations/000148_group_source.down.sql @@ -1,8 +1,4 @@ -BEGIN; - ALTER TABLE groups DROP COLUMN source; DROP TYPE group_source; - -COMMIT; diff --git a/coderd/database/migrations/000148_group_source.up.sql b/coderd/database/migrations/000148_group_source.up.sql index d06e89ca2b..d4b7140ebc 100644 --- a/coderd/database/migrations/000148_group_source.up.sql +++ b/coderd/database/migrations/000148_group_source.up.sql @@ -1,5 +1,3 @@ -BEGIN; - CREATE TYPE group_source AS ENUM ( -- User created groups 'user', @@ -11,5 +9,3 @@ ALTER TABLE groups ADD COLUMN source group_source NOT NULL DEFAULT 'user'; COMMENT ON COLUMN groups.source IS 'Source indicates how the group was created. It can be created by a user manually, or through some system process like OIDC group sync.'; - -COMMIT; diff --git a/coderd/database/migrations/000149_agent_multiple_subsystems.down.sql b/coderd/database/migrations/000149_agent_multiple_subsystems.down.sql index 05bea6c620..be5d71f14d 100644 --- a/coderd/database/migrations/000149_agent_multiple_subsystems.down.sql +++ b/coderd/database/migrations/000149_agent_multiple_subsystems.down.sql @@ -1,5 +1,3 @@ -BEGIN; - -- Bring back the subsystem column. ALTER TABLE workspace_agents ADD COLUMN subsystem workspace_agent_subsystem NOT NULL DEFAULT 'none'; @@ -13,5 +11,3 @@ ALTER TABLE workspace_agents DROP COLUMN subsystems; -- We cannot drop the "exectrace" value from the workspace_agent_subsystem type -- because you cannot drop values from an enum type. UPDATE workspace_agents SET subsystem = 'none' WHERE subsystem = 'exectrace'; - -COMMIT; diff --git a/coderd/database/migrations/000149_agent_multiple_subsystems.up.sql b/coderd/database/migrations/000149_agent_multiple_subsystems.up.sql index 9ebb71d5bd..f39cf5ab06 100644 --- a/coderd/database/migrations/000149_agent_multiple_subsystems.up.sql +++ b/coderd/database/migrations/000149_agent_multiple_subsystems.up.sql @@ -1,5 +1,3 @@ -BEGIN; - -- Add "exectrace" to workspace_agent_subsystem type. ALTER TYPE workspace_agent_subsystem ADD VALUE 'exectrace'; @@ -17,5 +15,3 @@ UPDATE workspace_agents SET subsystems = ARRAY[subsystem] WHERE subsystem != 'no -- Drop the subsystem column from workspace_agents. ALTER TABLE workspace_agents DROP COLUMN subsystem; - -COMMIT; diff --git a/coderd/database/migrations/000151_rename_locked.down.sql b/coderd/database/migrations/000151_rename_locked.down.sql index 4dfb254268..6be23ffdfc 100644 --- a/coderd/database/migrations/000151_rename_locked.down.sql +++ b/coderd/database/migrations/000151_rename_locked.down.sql @@ -1,5 +1,3 @@ -BEGIN; - ALTER TABLE templates RENAME COLUMN time_til_dormant TO inactivity_ttl; ALTER TABLE templates RENAME COLUMN time_til_dormant_autodelete TO locked_ttl; ALTER TABLE workspaces RENAME COLUMN dormant_at TO locked_at; @@ -22,5 +20,3 @@ AS templates.created_by = visible_users.id; COMMENT ON VIEW template_with_users IS 'Joins in the username + avatar url of the created by user.'; - -COMMIT; diff --git a/coderd/database/migrations/000151_rename_locked.up.sql b/coderd/database/migrations/000151_rename_locked.up.sql index ae72c7efa9..957c45ff4e 100644 --- a/coderd/database/migrations/000151_rename_locked.up.sql +++ b/coderd/database/migrations/000151_rename_locked.up.sql @@ -1,4 +1,3 @@ -BEGIN; ALTER TABLE templates RENAME COLUMN inactivity_ttl TO time_til_dormant; ALTER TABLE templates RENAME COLUMN locked_ttl TO time_til_dormant_autodelete; ALTER TABLE workspaces RENAME COLUMN locked_at TO dormant_at; @@ -21,5 +20,3 @@ AS templates.created_by = visible_users.id; COMMENT ON VIEW template_with_users IS 'Joins in the username + avatar url of the created by user.'; - -COMMIT; diff --git a/coderd/database/migrations/000152_rename_template_restart_requirement.down.sql b/coderd/database/migrations/000152_rename_template_restart_requirement.down.sql index 1dc90e708d..92841b2c0d 100644 --- a/coderd/database/migrations/000152_rename_template_restart_requirement.down.sql +++ b/coderd/database/migrations/000152_rename_template_restart_requirement.down.sql @@ -1,5 +1,3 @@ -BEGIN; - DROP VIEW template_with_users; ALTER TABLE templates RENAME COLUMN autostop_requirement_days_of_week TO restart_requirement_days_of_week; @@ -21,5 +19,3 @@ AS templates.created_by = visible_users.id; COMMENT ON VIEW template_with_users IS 'Joins in the username + avatar url of the created by user.'; - -COMMIT; diff --git a/coderd/database/migrations/000152_rename_template_restart_requirement.up.sql b/coderd/database/migrations/000152_rename_template_restart_requirement.up.sql index 6732328751..0e006d9c6e 100644 --- a/coderd/database/migrations/000152_rename_template_restart_requirement.up.sql +++ b/coderd/database/migrations/000152_rename_template_restart_requirement.up.sql @@ -1,5 +1,3 @@ -BEGIN; - DROP VIEW template_with_users; ALTER TABLE templates RENAME COLUMN restart_requirement_days_of_week TO autostop_requirement_days_of_week; @@ -21,5 +19,3 @@ AS templates.created_by = visible_users.id; COMMENT ON VIEW template_with_users IS 'Joins in the username + avatar url of the created by user.'; - -COMMIT; diff --git a/coderd/database/migrations/000153_agent_default_apps.down.sql b/coderd/database/migrations/000153_agent_default_apps.down.sql index 34c8f46551..234dc2c2f4 100644 --- a/coderd/database/migrations/000153_agent_default_apps.down.sql +++ b/coderd/database/migrations/000153_agent_default_apps.down.sql @@ -1,5 +1,2 @@ -BEGIN; ALTER TABLE workspace_agents DROP COLUMN display_apps; -DROP TYPE display_app; -COMMIT; - +DROP TYPE display_app; diff --git a/coderd/database/migrations/000153_agent_default_apps.up.sql b/coderd/database/migrations/000153_agent_default_apps.up.sql index 7b51b77d86..a269d4d5c7 100644 --- a/coderd/database/migrations/000153_agent_default_apps.up.sql +++ b/coderd/database/migrations/000153_agent_default_apps.up.sql @@ -1,4 +1,2 @@ -BEGIN; CREATE TYPE display_app AS ENUM ('vscode', 'vscode_insiders', 'web_terminal', 'ssh_helper', 'port_forwarding_helper'); ALTER TABLE workspace_agents ADD column display_apps display_app[] DEFAULT '{vscode, vscode_insiders, web_terminal, ssh_helper, port_forwarding_helper}'; -COMMIT; diff --git a/coderd/database/migrations/000154_dbcrypt_key_ids.down.sql b/coderd/database/migrations/000154_dbcrypt_key_ids.down.sql index 7dea0a1909..01e200ccc8 100644 --- a/coderd/database/migrations/000154_dbcrypt_key_ids.down.sql +++ b/coderd/database/migrations/000154_dbcrypt_key_ids.down.sql @@ -1,5 +1,3 @@ -BEGIN; - -- Before dropping this table, we need to check if there exist any -- foreign key references to it. We do this by checking the following: -- user_links.oauth_access_token_key_id @@ -39,5 +37,3 @@ ALTER TABLE user_links -- Finally, drop the table. DROP TABLE IF EXISTS dbcrypt_keys; - -COMMIT; diff --git a/coderd/database/migrations/000156_pg_coordinator_single_tailnet.down.sql b/coderd/database/migrations/000156_pg_coordinator_single_tailnet.down.sql index 7cc418489f..3b35e0015a 100644 --- a/coderd/database/migrations/000156_pg_coordinator_single_tailnet.down.sql +++ b/coderd/database/migrations/000156_pg_coordinator_single_tailnet.down.sql @@ -1,5 +1,3 @@ -BEGIN; - ALTER TABLE tailnet_clients ADD COLUMN @@ -35,5 +33,3 @@ BEGIN END IF; END; $$; - -COMMIT; diff --git a/coderd/database/migrations/000156_pg_coordinator_single_tailnet.up.sql b/coderd/database/migrations/000156_pg_coordinator_single_tailnet.up.sql index 4ca218248e..4bb76f8e28 100644 --- a/coderd/database/migrations/000156_pg_coordinator_single_tailnet.up.sql +++ b/coderd/database/migrations/000156_pg_coordinator_single_tailnet.up.sql @@ -1,5 +1,3 @@ -BEGIN; - CREATE TABLE tailnet_client_subscriptions ( client_id uuid NOT NULL, coordinator_id uuid NOT NULL, @@ -84,5 +82,3 @@ ALTER TABLE tailnet_clients DROP COLUMN agent_id; - -COMMIT; diff --git a/coderd/database/migrations/000157_workspace_agent_script.down.sql b/coderd/database/migrations/000157_workspace_agent_script.down.sql index 013c1097dd..2135665470 100644 --- a/coderd/database/migrations/000157_workspace_agent_script.down.sql +++ b/coderd/database/migrations/000157_workspace_agent_script.down.sql @@ -1,5 +1,3 @@ -BEGIN; - ALTER TABLE workspace_agent_logs SET LOGGED; -- Revert the workspace_agents table to its former state @@ -19,5 +17,3 @@ ALTER TABLE workspace_agent_logs DROP COLUMN log_source_id; -- Drop the newly created tables DROP TABLE workspace_agent_scripts; DROP TABLE workspace_agent_log_sources; - -COMMIT; diff --git a/coderd/database/migrations/000157_workspace_agent_script.up.sql b/coderd/database/migrations/000157_workspace_agent_script.up.sql index c073318c5b..3b7244951f 100644 --- a/coderd/database/migrations/000157_workspace_agent_script.up.sql +++ b/coderd/database/migrations/000157_workspace_agent_script.up.sql @@ -1,4 +1,3 @@ -BEGIN; CREATE TABLE workspace_agent_log_sources ( workspace_agent_id uuid NOT NULL REFERENCES workspace_agents(id) ON DELETE CASCADE, id uuid NOT NULL, @@ -33,4 +32,3 @@ ALTER TABLE workspace_agents DROP COLUMN startup_script; -- Set the table to unlogged to speed up the inserts ALTER TABLE workspace_agent_logs SET UNLOGGED; -COMMIT; diff --git a/coderd/database/migrations/000158_external_auth.down.sql b/coderd/database/migrations/000158_external_auth.down.sql index 427de53c95..a2f48a2c64 100644 --- a/coderd/database/migrations/000158_external_auth.down.sql +++ b/coderd/database/migrations/000158_external_auth.down.sql @@ -1,5 +1,3 @@ -BEGIN; - ALTER TABLE template_versions RENAME COLUMN external_auth_providers TO git_auth_providers; ALTER TABLE external_auth_links RENAME TO git_auth_links; @@ -21,5 +19,3 @@ FROM template_versions.created_by = visible_users.id; COMMENT ON VIEW template_version_with_user IS 'Joins in the username + avatar url of the created by user.'; - -COMMIT; diff --git a/coderd/database/migrations/000158_external_auth.up.sql b/coderd/database/migrations/000158_external_auth.up.sql index 52fc1977e3..3ae295bb24 100644 --- a/coderd/database/migrations/000158_external_auth.up.sql +++ b/coderd/database/migrations/000158_external_auth.up.sql @@ -1,5 +1,3 @@ -BEGIN; - ALTER TABLE template_versions RENAME COLUMN git_auth_providers TO external_auth_providers; ALTER TABLE git_auth_links RENAME TO external_auth_links; @@ -23,5 +21,3 @@ FROM COMMENT ON VIEW template_version_with_user IS 'Joins in the username + avatar url of the created by user.'; COMMENT ON COLUMN template_versions.external_auth_providers IS 'IDs of External auth providers for a specific template version'; - -COMMIT; diff --git a/coderd/database/migrations/000160_provisioner_job_status.down.sql b/coderd/database/migrations/000160_provisioner_job_status.down.sql index 3f04c8dd11..db71dfa84e 100644 --- a/coderd/database/migrations/000160_provisioner_job_status.down.sql +++ b/coderd/database/migrations/000160_provisioner_job_status.down.sql @@ -1,6 +1,2 @@ -BEGIN; - ALTER TABLE provisioner_jobs DROP COLUMN job_status; DROP TYPE provisioner_job_status; - -COMMIT; diff --git a/coderd/database/migrations/000160_provisioner_job_status.up.sql b/coderd/database/migrations/000160_provisioner_job_status.up.sql index 9cfea7fbfb..d6b310d7a9 100644 --- a/coderd/database/migrations/000160_provisioner_job_status.up.sql +++ b/coderd/database/migrations/000160_provisioner_job_status.up.sql @@ -1,5 +1,3 @@ -BEGIN; - CREATE TYPE provisioner_job_status AS ENUM ('pending', 'running', 'succeeded', 'canceling', 'canceled', 'failed', 'unknown'); COMMENT ON TYPE provisioner_job_status IS 'Computed status of a provisioner job. Jobs could be stuck in a hung state, these states do not guarantee any transition to another state.'; @@ -34,5 +32,3 @@ ALTER TABLE provisioner_jobs ADD COLUMN COMMENT ON COLUMN provisioner_jobs.job_status IS 'Computed column to track the status of the job.'; - -COMMIT; diff --git a/coderd/database/migrations/000162_workspace_automatic_updates.down.sql b/coderd/database/migrations/000162_workspace_automatic_updates.down.sql index d2f050b4af..57ce2c1cd7 100644 --- a/coderd/database/migrations/000162_workspace_automatic_updates.down.sql +++ b/coderd/database/migrations/000162_workspace_automatic_updates.down.sql @@ -1,4 +1,2 @@ -BEGIN; ALTER TABLE workspaces DROP COLUMN IF EXISTS automatic_updates; DROP TYPE IF EXISTS automatic_updates; -COMMIT; diff --git a/coderd/database/migrations/000162_workspace_automatic_updates.up.sql b/coderd/database/migrations/000162_workspace_automatic_updates.up.sql index b034437007..0e773421a6 100644 --- a/coderd/database/migrations/000162_workspace_automatic_updates.up.sql +++ b/coderd/database/migrations/000162_workspace_automatic_updates.up.sql @@ -1,8 +1,6 @@ -BEGIN; -- making this an enum in case we want to later add other options, like 'if_compatible_vars' CREATE TYPE automatic_updates AS ENUM ( 'always', 'never' ); ALTER TABLE workspaces ADD COLUMN IF NOT EXISTS automatic_updates automatic_updates NOT NULL DEFAULT 'never'::automatic_updates; -COMMIT; diff --git a/coderd/database/migrations/000164_archive_template_versions.down.sql b/coderd/database/migrations/000164_archive_template_versions.down.sql index 2c89f985aa..0a0b82b972 100644 --- a/coderd/database/migrations/000164_archive_template_versions.down.sql +++ b/coderd/database/migrations/000164_archive_template_versions.down.sql @@ -1,5 +1,3 @@ -BEGIN; - -- The view will be rebuilt with the new column DROP VIEW template_version_with_user; @@ -22,5 +20,3 @@ FROM template_versions.created_by = visible_users.id; COMMENT ON VIEW template_version_with_user IS 'Joins in the username + avatar url of the created by user.'; - -COMMIT; diff --git a/coderd/database/migrations/000164_archive_template_versions.up.sql b/coderd/database/migrations/000164_archive_template_versions.up.sql index d18d4cdfe4..0be61ebde0 100644 --- a/coderd/database/migrations/000164_archive_template_versions.up.sql +++ b/coderd/database/migrations/000164_archive_template_versions.up.sql @@ -1,5 +1,3 @@ -BEGIN; - -- The view will be rebuilt with the new column DROP VIEW template_version_with_user; @@ -23,5 +21,3 @@ FROM template_versions.created_by = visible_users.id; COMMENT ON VIEW template_version_with_user IS 'Joins in the username + avatar url of the created by user.'; - -COMMIT; diff --git a/coderd/database/migrations/000165_prevent_autostart_days.down.sql b/coderd/database/migrations/000165_prevent_autostart_days.down.sql index c4f3351eea..698b6edfea 100644 --- a/coderd/database/migrations/000165_prevent_autostart_days.down.sql +++ b/coderd/database/migrations/000165_prevent_autostart_days.down.sql @@ -1,5 +1,3 @@ -BEGIN; - DROP VIEW template_with_users; ALTER TABLE templates @@ -21,5 +19,3 @@ FROM templates.created_by = visible_users.id; COMMENT ON VIEW template_with_users IS 'Joins in the username + avatar url of the created by user.'; - -COMMIT; diff --git a/coderd/database/migrations/000165_prevent_autostart_days.up.sql b/coderd/database/migrations/000165_prevent_autostart_days.up.sql index 79c2c2a5e5..3302b4f491 100644 --- a/coderd/database/migrations/000165_prevent_autostart_days.up.sql +++ b/coderd/database/migrations/000165_prevent_autostart_days.up.sql @@ -1,5 +1,3 @@ -BEGIN; - DROP VIEW template_with_users; ALTER TABLE templates @@ -23,5 +21,3 @@ FROM templates.created_by = visible_users.id; COMMENT ON VIEW template_with_users IS 'Joins in the username + avatar url of the created by user.'; - -COMMIT; diff --git a/coderd/database/migrations/000166_template_active_version.down.sql b/coderd/database/migrations/000166_template_active_version.down.sql index d3b4bba305..21c2cfd026 100644 --- a/coderd/database/migrations/000166_template_active_version.down.sql +++ b/coderd/database/migrations/000166_template_active_version.down.sql @@ -1,5 +1,3 @@ -BEGIN; - -- Update the template_with_users view; DROP VIEW template_with_users; @@ -21,5 +19,3 @@ AS templates.created_by = visible_users.id; COMMENT ON VIEW template_with_users IS 'Joins in the username + avatar url of the created by user.'; - -COMMIT; diff --git a/coderd/database/migrations/000166_template_active_version.up.sql b/coderd/database/migrations/000166_template_active_version.up.sql index a9255505ee..726a72cf24 100644 --- a/coderd/database/migrations/000166_template_active_version.up.sql +++ b/coderd/database/migrations/000166_template_active_version.up.sql @@ -1,5 +1,3 @@ -BEGIN; - DROP VIEW template_with_users; ALTER TABLE templates ADD COLUMN require_active_version boolean NOT NULL DEFAULT 'f'; @@ -19,5 +17,3 @@ AS templates.created_by = visible_users.id; COMMENT ON VIEW template_with_users IS 'Joins in the username + avatar url of the created by user.'; - -COMMIT; diff --git a/coderd/database/migrations/000167_workspace_agent_api_version.down.sql b/coderd/database/migrations/000167_workspace_agent_api_version.down.sql index 53c2b3417a..1d2e661596 100644 --- a/coderd/database/migrations/000167_workspace_agent_api_version.down.sql +++ b/coderd/database/migrations/000167_workspace_agent_api_version.down.sql @@ -1,3 +1 @@ -BEGIN; ALTER TABLE workspace_agents DROP COLUMN api_version; -COMMIT; diff --git a/coderd/database/migrations/000167_workspace_agent_api_version.up.sql b/coderd/database/migrations/000167_workspace_agent_api_version.up.sql index b4187e51ef..143ac0f5c7 100644 --- a/coderd/database/migrations/000167_workspace_agent_api_version.up.sql +++ b/coderd/database/migrations/000167_workspace_agent_api_version.up.sql @@ -1,3 +1 @@ -BEGIN; ALTER TABLE workspace_agents ADD COLUMN api_version TEXT DEFAULT '' NOT NULL; -COMMIT; diff --git a/coderd/database/migrations/000168_pg_coord_tailnet_v2_api.down.sql b/coderd/database/migrations/000168_pg_coord_tailnet_v2_api.down.sql index 084c00e922..6b8c844157 100644 --- a/coderd/database/migrations/000168_pg_coord_tailnet_v2_api.down.sql +++ b/coderd/database/migrations/000168_pg_coord_tailnet_v2_api.down.sql @@ -1,5 +1,3 @@ -BEGIN; - DROP TRIGGER IF EXISTS tailnet_notify_tunnel_change ON tailnet_tunnels; DROP FUNCTION IF EXISTS tailnet_notify_tunnel_change; DROP TABLE IF EXISTS tailnet_tunnels; @@ -10,5 +8,3 @@ DROP INDEX IF EXISTS idx_tailnet_peers_coordinator; DROP TABLE IF EXISTS tailnet_peers; DROP TYPE IF EXISTS tailnet_status; - -COMMIT; diff --git a/coderd/database/migrations/000168_pg_coord_tailnet_v2_api.up.sql b/coderd/database/migrations/000168_pg_coord_tailnet_v2_api.up.sql index 9839c59a33..6d9029543a 100644 --- a/coderd/database/migrations/000168_pg_coord_tailnet_v2_api.up.sql +++ b/coderd/database/migrations/000168_pg_coord_tailnet_v2_api.up.sql @@ -1,5 +1,3 @@ -BEGIN; - CREATE TYPE tailnet_status AS ENUM ( 'ok', 'lost' @@ -68,5 +66,3 @@ CREATE TRIGGER tailnet_notify_tunnel_change AFTER INSERT OR UPDATE OR DELETE ON tailnet_tunnels FOR EACH ROW EXECUTE PROCEDURE tailnet_notify_tunnel_change(); - -COMMIT; diff --git a/coderd/database/migrations/000169_deprecate_template.down.sql b/coderd/database/migrations/000169_deprecate_template.down.sql index 3d944135ae..c7e719efae 100644 --- a/coderd/database/migrations/000169_deprecate_template.down.sql +++ b/coderd/database/migrations/000169_deprecate_template.down.sql @@ -1,5 +1,3 @@ -BEGIN; - DROP VIEW template_with_users; ALTER TABLE templates @@ -20,5 +18,3 @@ FROM templates.created_by = visible_users.id; COMMENT ON VIEW template_with_users IS 'Joins in the username + avatar url of the created by user.'; - -COMMIT; diff --git a/coderd/database/migrations/000169_deprecate_template.up.sql b/coderd/database/migrations/000169_deprecate_template.up.sql index 3e688a6bef..d09e1a3d77 100644 --- a/coderd/database/migrations/000169_deprecate_template.up.sql +++ b/coderd/database/migrations/000169_deprecate_template.up.sql @@ -1,5 +1,3 @@ -BEGIN; - -- The view will be rebuilt with the new column DROP VIEW template_with_users; @@ -24,5 +22,3 @@ FROM templates.created_by = visible_users.id; COMMENT ON VIEW template_with_users IS 'Joins in the username + avatar url of the created by user.'; - -COMMIT; diff --git a/coderd/database/migrations/000170_workspaceproxy_version.down.sql b/coderd/database/migrations/000170_workspaceproxy_version.down.sql index 55810705b0..7e5afd3441 100644 --- a/coderd/database/migrations/000170_workspaceproxy_version.down.sql +++ b/coderd/database/migrations/000170_workspaceproxy_version.down.sql @@ -1,3 +1 @@ -BEGIN; ALTER TABLE workspace_proxies DROP COLUMN version; -COMMIT; diff --git a/coderd/database/migrations/000170_workspaceproxy_version.up.sql b/coderd/database/migrations/000170_workspaceproxy_version.up.sql index a7e3519126..6d88df8c08 100644 --- a/coderd/database/migrations/000170_workspaceproxy_version.up.sql +++ b/coderd/database/migrations/000170_workspaceproxy_version.up.sql @@ -1,3 +1 @@ -BEGIN; ALTER TABLE workspace_proxies ADD COLUMN version TEXT DEFAULT ''::TEXT NOT NULL; -COMMIT; diff --git a/coderd/database/migrations/000171_oidc_debug_claims.down.sql b/coderd/database/migrations/000171_oidc_debug_claims.down.sql index 60952cd351..de9d3b72b2 100644 --- a/coderd/database/migrations/000171_oidc_debug_claims.down.sql +++ b/coderd/database/migrations/000171_oidc_debug_claims.down.sql @@ -1,5 +1 @@ -BEGIN; - ALTER TABLE user_links DROP COLUMN debug_context; - -COMMIT; diff --git a/coderd/database/migrations/000171_oidc_debug_claims.up.sql b/coderd/database/migrations/000171_oidc_debug_claims.up.sql index c46be45767..81afead9b2 100644 --- a/coderd/database/migrations/000171_oidc_debug_claims.up.sql +++ b/coderd/database/migrations/000171_oidc_debug_claims.up.sql @@ -1,6 +1,2 @@ -BEGIN; - ALTER TABLE user_links ADD COLUMN debug_context jsonb DEFAULT '{}' NOT NULL; COMMENT ON COLUMN user_links.debug_context IS 'Debug information includes information like id_token and userinfo claims.'; - -COMMIT; diff --git a/coderd/database/migrations/create_migration.sh b/coderd/database/migrations/create_migration.sh index 3046e875e3..aac112c429 100755 --- a/coderd/database/migrations/create_migration.sh +++ b/coderd/database/migrations/create_migration.sh @@ -7,6 +7,34 @@ set -euo pipefail +cat <= 0 { + query = `INSERT INTO ` + migrationsTableName + ` (version, dirty) VALUES ($1, $2)` + if _, err := d.tx.Exec(query, version, dirty); err != nil { + return &database.Error{OrigErr: err, Query: []byte(query)} + } + } + + return nil +} + +func (d *pgTxnDriver) Version() (version int, dirty bool, err error) { + // If the transaction is valid (we hold the exclusive lock), use the txn for + // the query. + var q interface { + QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row + } = d.tx + // If we don't hold the lock just use the database. This only happens in the + // `Stepper` function and is only used in tests. + if d.tx == nil { + q = d.db + } + + query := `SELECT version, dirty FROM ` + migrationsTableName + ` LIMIT 1` + err = q.QueryRowContext(context.Background(), query).Scan(&version, &dirty) + switch { + case err == sql.ErrNoRows: + return database.NilVersion, false, nil + + case err != nil: + var pgErr *pq.Error + if xerrors.As(err, &pgErr) { + if pgErr.Code.Name() == "undefined_table" { + return database.NilVersion, false, nil + } + } + return 0, false, &database.Error{OrigErr: err, Query: []byte(query)} + + default: + return version, dirty, nil + } +} + +func (*pgTxnDriver) Drop() error { + panic("not implemented") +} + +func (d *pgTxnDriver) ensureVersionTable() error { + err := d.Lock() + if err != nil { + return xerrors.Errorf("acquire migration lock: %w", err) + } + + const query = `CREATE TABLE IF NOT EXISTS ` + migrationsTableName + ` (version bigint not null primary key, dirty boolean not null)` + if _, err := d.tx.ExecContext(context.Background(), query); err != nil { + return &database.Error{OrigErr: err, Query: []byte(query)} + } + + err = d.Unlock() + if err != nil { + return xerrors.Errorf("release migration lock: %w", err) + } + + return nil +} diff --git a/coderd/database/models.go b/coderd/database/models.go index bd7625657b..c3e4fdf42f 100644 --- a/coderd/database/models.go +++ b/coderd/database/models.go @@ -1350,7 +1350,7 @@ func AllTailnetStatusValues() []TailnetStatus { } } -// Defines the user status: active, dormant, or suspended. +// Defines the users status: active, dormant, or suspended. type UserStatus string const (