feat: run all migrations in a transaction (#10966)

Updates coder/customers#365

This PR updates our migration framework to run all migrations in a single transaction. This is the same behavior we had in v1 and ensures that failed migrations don't bring the whole deployment down. If a migration fails now, it will automatically be rolled back to the previous version, allowing the deployment to continue functioning.
This commit is contained in:
Colin Adler
2023-12-01 16:11:10 -06:00
committed by GitHub
parent 60d0aa6930
commit 8e684c8195
109 changed files with 243 additions and 372 deletions

View File

@ -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',

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -1,5 +1 @@
BEGIN;
ALTER TABLE groups DROP COLUMN avatar_url;
COMMIT;

View File

@ -1,5 +1 @@
BEGIN;
ALTER TABLE groups ADD COLUMN avatar_url text NOT NULL DEFAULT '';
COMMIT;

View File

@ -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';

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -1,9 +1,5 @@
BEGIN;
ALTER TABLE workspace_agents
DROP COLUMN connection_timeout_seconds;
ALTER TABLE workspace_agents
DROP COLUMN troubleshooting_url;
COMMIT;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -1,6 +1,2 @@
BEGIN;
ALTER TABLE ONLY workspace_agents
DROP COLUMN IF EXISTS expanded_directory;
COMMIT;

View File

@ -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;

View File

@ -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;

View File

@ -1,8 +1,4 @@
BEGIN;
DROP INDEX idx_api_key_name;
ALTER TABLE ONLY api_keys
DROP COLUMN IF EXISTS token_name;
COMMIT;

View File

@ -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;

View File

@ -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;

View File

@ -1,4 +1 @@
BEGIN;
DROP TABLE workspace_proxies;
COMMIT;

View File

@ -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;

View File

@ -1,6 +1,2 @@
BEGIN;
ALTER TABLE workspace_proxies
DROP COLUMN token_hashed_secret;
COMMIT;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -1,4 +1,2 @@
BEGIN;
ALTER TABLE workspace_agents DROP COLUMN subsystem;
DROP TYPE workspace_agent_subsystem;
COMMIT;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -1,3 +1 @@
BEGIN;
ALTER TABLE templates DROP COLUMN locked_ttl;
COMMIT;

View File

@ -1,3 +1 @@
BEGIN;
ALTER TABLE templates ADD COLUMN locked_ttl BIGINT NOT NULL DEFAULT 0;
COMMIT;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -1,3 +1 @@
BEGIN;
ALTER TABLE workspaces DROP COLUMN locked_at;
COMMIT;

View File

@ -1,3 +1 @@
BEGIN;
ALTER TABLE workspaces ADD COLUMN locked_at timestamptz NULL;
COMMIT;

View File

@ -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;

View File

@ -1,6 +1,2 @@
BEGIN;
DROP VIEW template_with_users;
DROP VIEW visible_users;
COMMIT;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -1,6 +1,2 @@
BEGIN;
DROP VIEW workspace_build_with_user;
DROP VIEW template_version_with_user;
COMMIT;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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';

View File

@ -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;

View File

@ -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;

View File

@ -1,6 +1,2 @@
BEGIN;
ALTER TABLE groups
DROP COLUMN display_name;
COMMIT;

View File

@ -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;

View File

@ -1,8 +1,4 @@
BEGIN;
ALTER TABLE groups
DROP COLUMN source;
DROP TYPE group_source;
COMMIT;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -1,5 +1,2 @@
BEGIN;
ALTER TABLE workspace_agents DROP COLUMN display_apps;
DROP TYPE display_app;
COMMIT;
DROP TYPE display_app;

View File

@ -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;

View File

@ -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;

View File

@ -1,5 +1,3 @@
BEGIN;
ALTER TABLE
tailnet_clients
ADD COLUMN
@ -35,5 +33,3 @@ BEGIN
END IF;
END;
$$;
COMMIT;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -1,6 +1,2 @@
BEGIN;
ALTER TABLE provisioner_jobs DROP COLUMN job_status;
DROP TYPE provisioner_job_status;
COMMIT;

View File

@ -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;

View File

@ -1,4 +1,2 @@
BEGIN;
ALTER TABLE workspaces DROP COLUMN IF EXISTS automatic_updates;
DROP TYPE IF EXISTS automatic_updates;
COMMIT;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -1,3 +1 @@
BEGIN;
ALTER TABLE workspace_agents DROP COLUMN api_version;
COMMIT;

View File

@ -1,3 +1 @@
BEGIN;
ALTER TABLE workspace_agents ADD COLUMN api_version TEXT DEFAULT '' NOT NULL;
COMMIT;

View File

@ -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;

View File

@ -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;

View File

@ -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;

Some files were not shown because too many files have changed in this diff Show More