mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: add new required slug property to coder_app, use in URLs (#4573)
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
-- drop unique index on "slug" column
|
||||
ALTER TABLE "workspace_apps" DROP CONSTRAINT IF EXISTS "workspace_apps_agent_id_slug_idx";
|
||||
|
||||
-- drop "slug" column from "workspace_apps" table
|
||||
ALTER TABLE "workspace_apps" DROP COLUMN "slug";
|
||||
@@ -0,0 +1,16 @@
|
||||
BEGIN;
|
||||
|
||||
-- add "slug" column to "workspace_apps" table
|
||||
ALTER TABLE "workspace_apps" ADD COLUMN "slug" text DEFAULT '';
|
||||
|
||||
-- copy the "name" column for each workspace app to the "slug" column
|
||||
UPDATE "workspace_apps" SET "slug" = "name";
|
||||
|
||||
-- make "slug" column not nullable and remove default
|
||||
ALTER TABLE "workspace_apps" ALTER COLUMN "slug" SET NOT NULL;
|
||||
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;
|
||||
@@ -0,0 +1,34 @@
|
||||
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 (
|
||||
SELECT
|
||||
*,
|
||||
row_number() OVER (PARTITION BY agent_id, display_name ORDER BY display_name ASC) AS row_number
|
||||
FROM
|
||||
workspace_apps
|
||||
)
|
||||
|
||||
-- Update any app with a "row_number" greater than 1 to have the row number
|
||||
-- appended to the display name. This effectively means that all lowercase
|
||||
-- display names remain untouched, while non-unique mixed case usernames are
|
||||
-- appended with a unique number. If you had three apps called all called asdf,
|
||||
-- they would then be renamed to e.g. asdf, asdf1234, and asdf5678.
|
||||
UPDATE
|
||||
workspace_apps
|
||||
SET
|
||||
display_name = workspace_apps.display_name || floor(random() * 10000)::text
|
||||
FROM
|
||||
row_numbers
|
||||
WHERE
|
||||
workspace_apps.id = row_numbers.id AND
|
||||
row_numbers.row_number > 1;
|
||||
|
||||
-- rename column "display_name" to "name" on "workspace_apps"
|
||||
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;
|
||||
@@ -0,0 +1,9 @@
|
||||
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;
|
||||
Reference in New Issue
Block a user