Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions dirs/coder/migrations/20260715153434.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- Modify "api_keys" table
ALTER TABLE "api_keys" DROP CONSTRAINT "api_keys_expires_at_not_before_last_used", ADD CONSTRAINT "api_keys_expires_at_not_before_last_used" CHECK (expires_at >= last_used_at), DROP CONSTRAINT "api_keys_last_used_not_before_sentinel", ADD CONSTRAINT "api_keys_last_used_not_before_sentinel" CHECK (last_used_at >= '0001-01-01 00:00:00+00'::timestamp with time zone), DROP COLUMN "last_used", ADD COLUMN "last_used_at" timestamptz NOT NULL;

Check failure on line 2 in dirs/coder/migrations/20260715153434.sql

View workflow job for this annotation

GitHub Actions / atlas

data dependent changes detected

Adding a non-nullable "timestamptz" column "last_used_at" will fail in case table "api_keys" is not empty (MF103) Details: https://atlasgo.io/lint/analyzers#MF103

Check failure on line 2 in dirs/coder/migrations/20260715153434.sql

View workflow job for this annotation

GitHub Actions / atlas

destructive changes detected

Dropping non-virtual column "last_used" (DS103) Details: https://atlasgo.io/lint/analyzers#DS103
Comment on lines +1 to +2

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

destructive changes detected
Dropping non-virtual column "last_used" DS103

Add a pre-migration check to ensure column "last_used" is NULL before dropping it

Suggested change
-- Modify "api_keys" table
ALTER TABLE "api_keys" DROP CONSTRAINT "api_keys_expires_at_not_before_last_used", ADD CONSTRAINT "api_keys_expires_at_not_before_last_used" CHECK (expires_at >= last_used_at), DROP CONSTRAINT "api_keys_last_used_not_before_sentinel", ADD CONSTRAINT "api_keys_last_used_not_before_sentinel" CHECK (last_used_at >= '0001-01-01 00:00:00+00'::timestamp with time zone), DROP COLUMN "last_used", ADD COLUMN "last_used_at" timestamptz NOT NULL;
-- atlas:txtar
-- checks/destructive.sql --
-- atlas:assert DS103
SELECT NOT EXISTS (SELECT 1 FROM "public"."api_keys" WHERE "last_used" IS NOT NULL) AS "is_empty";
-- migration.sql --
-- Modify "api_keys" table
ALTER TABLE "api_keys" DROP CONSTRAINT "api_keys_expires_at_not_before_last_used", ADD CONSTRAINT "api_keys_expires_at_not_before_last_used" CHECK (expires_at >= last_used_at), DROP CONSTRAINT "api_keys_last_used_not_before_sentinel", ADD CONSTRAINT "api_keys_last_used_not_before_sentinel" CHECK (last_used_at >= '0001-01-01 00:00:00+00'::timestamp with time zone), DROP COLUMN "last_used", ADD COLUMN "last_used_at" timestamptz NOT NULL;

Ensure to run atlas migrate hash --dir "file://dirs/coder/migrations" after applying the suggested changes.

3 changes: 2 additions & 1 deletion dirs/coder/migrations/atlas.sum
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
h1:Xow5vrkYyq9fDu4ypd4GuVOziNIHLz6eNzvJ5uIsa1Q=
h1:O84kvpde0vh4XjFabK26A6TJw5dJycsEZAQ0et9+u/g=
20251231090037_initial.sql h1:U5btCTuW+yflxpBpF1HoT9wp65mIiVYACHJeMQDOz+w=
20251231091921.sql h1:11zz1Nrb2G45QCbRrGub10D2vZuzdJbY6PkYXzrvsQg=
20251231150752.sql h1:kIQVr/QD6yFkwJonS3JQa0/UXWwbRLVLgbnqTPrbaUk=
Expand Down Expand Up @@ -61,3 +61,4 @@ h1:Xow5vrkYyq9fDu4ypd4GuVOziNIHLz6eNzvJ5uIsa1Q=
20260708154845.sql h1:TkTk2T4D79UgFi1HvWxj1wntsi578gVWZeClthsTZWI=
20260710155111.sql h1:KurSVe2Z9NT3nA1BoSzJnEYrkY169nNeffVMebuxcK8=
20260713155709.sql h1:Tec2cRjDhADirEz8xBWo0A0tLyEVjWHMRE1EhxCqD+s=
20260715153434.sql h1:OLvFfcmxKd4MaujwQK+8Ih2SbUQsx7pDv3aum5krbrA=
6 changes: 3 additions & 3 deletions dirs/coder/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ CREATE TABLE "public"."api_keys" (
"id" text NOT NULL,
"hashed_secret" bytea NOT NULL,
"user_id" uuid NOT NULL,
"last_used" timestamptz NOT NULL,
"last_used_at" timestamptz NOT NULL,
"expires_at" timestamptz NOT NULL,
"created_at" timestamptz NOT NULL,
"updated_at" timestamptz NOT NULL,
Expand All @@ -112,9 +112,9 @@ CREATE TABLE "public"."api_keys" (
CONSTRAINT "api_keys_user_id_uuid_fkey" FOREIGN KEY ("user_id") REFERENCES "public"."users" ("id") ON UPDATE NO ACTION ON DELETE CASCADE,
CONSTRAINT "api_keys_lifetime_seconds_non_negative" CHECK (lifetime_seconds >= 0),
CONSTRAINT "api_keys_expires_at_not_before_created_at" CHECK (expires_at >= created_at),
CONSTRAINT "api_keys_expires_at_not_before_last_used" CHECK (expires_at >= last_used),
CONSTRAINT "api_keys_expires_at_not_before_last_used" CHECK (expires_at >= last_used_at),
CONSTRAINT "api_keys_token_name_no_surrounding_whitespace" CHECK (token_name = btrim(token_name)),
CONSTRAINT "api_keys_last_used_not_before_sentinel" CHECK (last_used >= TIMESTAMPTZ '0001-01-01 00:00:00+00'),
CONSTRAINT "api_keys_last_used_not_before_sentinel" CHECK (last_used_at >= TIMESTAMPTZ '0001-01-01 00:00:00+00'),
CONSTRAINT "api_keys_ip_address_not_unspecified_v6" CHECK (ip_address <> '::'::inet),
CONSTRAINT "api_keys_token_name_not_empty" CHECK (length(btrim(token_name)) > 0),
CONSTRAINT "api_keys_hashed_secret_not_empty" CHECK (octet_length(hashed_secret) > 0),
Expand Down
Loading