|
| 1 | +-- This migration creates tables and types for v1 if they do not exist. |
| 2 | +-- This allows v2 to operate independently of v1, but share data if it exists. |
| 3 | +-- |
| 4 | +-- All tables and types are stolen from: |
| 5 | +-- https://github.com/coder/m/blob/47b6fc383347b9f9fab424d829c482defd3e1fe2/product/coder/pkg/database/dump.sql |
| 6 | + |
| 7 | +DO $$ BEGIN |
| 8 | + CREATE TYPE login_type AS ENUM ( |
| 9 | + 'built-in', |
| 10 | + 'saml', |
| 11 | + 'oidc' |
| 12 | + ); |
| 13 | +EXCEPTION |
| 14 | + WHEN duplicate_object THEN null; |
| 15 | +END $$; |
| 16 | + |
| 17 | +DO $$ BEGIN |
| 18 | + CREATE TYPE userstatus AS ENUM ( |
| 19 | + 'active', |
| 20 | + 'dormant', |
| 21 | + 'decommissioned' |
| 22 | + ); |
| 23 | +EXCEPTION |
| 24 | + WHEN duplicate_object THEN null; |
| 25 | +END $$; |
| 26 | + |
| 27 | +CREATE TABLE IF NOT EXISTS users ( |
| 28 | + id text NOT NULL, |
| 29 | + email text NOT NULL, |
| 30 | + name text NOT NULL, |
| 31 | + revoked boolean NOT NULL, |
| 32 | + login_type login_type NOT NULL, |
| 33 | + hashed_password bytea NOT NULL, |
| 34 | + created_at timestamp with time zone NOT NULL, |
| 35 | + updated_at timestamp with time zone NOT NULL, |
| 36 | + temporary_password boolean DEFAULT false NOT NULL, |
| 37 | + avatar_hash text DEFAULT '' :: text NOT NULL, |
| 38 | + ssh_key_regenerated_at timestamp with time zone DEFAULT now() NOT NULL, |
| 39 | + username text DEFAULT '' :: text NOT NULL, |
| 40 | + dotfiles_git_uri text DEFAULT '' :: text NOT NULL, |
| 41 | + roles text [] DEFAULT '{site-member}' :: text [] NOT NULL, |
| 42 | + status userstatus DEFAULT 'active' :: public.userstatus NOT NULL, |
| 43 | + relatime timestamp with time zone DEFAULT now() NOT NULL, |
| 44 | + gpg_key_regenerated_at timestamp with time zone DEFAULT now() NOT NULL, |
| 45 | + _decomissioned boolean DEFAULT false NOT NULL, |
| 46 | + shell text DEFAULT '' :: text NOT NULL |
| 47 | +); |
| 48 | + |
| 49 | +CREATE TABLE IF NOT EXISTS organizations ( |
| 50 | + id text NOT NULL, |
| 51 | + name text NOT NULL, |
| 52 | + description text NOT NULL, |
| 53 | + created_at timestamp with time zone NOT NULL, |
| 54 | + updated_at timestamp with time zone NOT NULL, |
| 55 | + "default" boolean DEFAULT false NOT NULL, |
| 56 | + auto_off_threshold bigint DEFAULT '28800000000000' :: bigint NOT NULL, |
| 57 | + cpu_provisioning_rate real DEFAULT 4.0 NOT NULL, |
| 58 | + memory_provisioning_rate real DEFAULT 1.0 NOT NULL, |
| 59 | + workspace_auto_off boolean DEFAULT false NOT NULL |
| 60 | +); |
| 61 | + |
| 62 | +CREATE TABLE IF NOT EXISTS organization_members ( |
| 63 | + organization_id text NOT NULL, |
| 64 | + user_id text NOT NULL, |
| 65 | + created_at timestamp with time zone NOT NULL, |
| 66 | + updated_at timestamp with time zone NOT NULL, |
| 67 | + roles text [] DEFAULT '{organization-member}' :: text [] NOT NULL |
| 68 | +); |
| 69 | + |
| 70 | +CREATE TABLE IF NOT EXISTS api_keys ( |
| 71 | + id text NOT NULL, |
| 72 | + hashed_secret bytea NOT NULL, |
| 73 | + user_id text NOT NULL, |
| 74 | + application boolean NOT NULL, |
| 75 | + name text NOT NULL, |
| 76 | + last_used timestamp with time zone NOT NULL, |
| 77 | + expires_at timestamp with time zone NOT NULL, |
| 78 | + created_at timestamp with time zone NOT NULL, |
| 79 | + updated_at timestamp with time zone NOT NULL, |
| 80 | + login_type login_type NOT NULL, |
| 81 | + oidc_access_token text DEFAULT ''::text NOT NULL, |
| 82 | + oidc_refresh_token text DEFAULT ''::text NOT NULL, |
| 83 | + oidc_id_token text DEFAULT ''::text NOT NULL, |
| 84 | + oidc_expiry timestamp with time zone DEFAULT '0001-01-01 00:00:00+00'::timestamp with time zone NOT NULL, |
| 85 | + devurl_token boolean DEFAULT false NOT NULL |
| 86 | +); |
| 87 | + |
| 88 | +CREATE TABLE licenses ( |
| 89 | + id integer NOT NULL, |
| 90 | + license jsonb NOT NULL, |
| 91 | + created_at timestamp with time zone NOT NULL |
| 92 | +); |
0 commit comments