lemmy/migrations/2022-12-05-110642_registration_mode/up.sql
Dessalines be1389420b
Adding SQL format checking via pg_format / pgFormatter (#3740)
* SQL format checking, 1.

* SQL format checking, 2.

* SQL format checking, 3.

* SQL format checking, 4.

* SQL format checking, 5.

* Running pg_format

* Getting rid of comment.

* Upping pg_format version.

* Using git ls-files for sql format check.

* Fixing sql lints.

* Addressing PR comments.
2023-08-02 12:44:51 -04:00

41 lines
976 B
SQL

-- create enum for registration modes
CREATE TYPE registration_mode_enum AS enum (
'closed',
'require_application',
'open'
);
-- use this enum for registration mode setting
ALTER TABLE local_site
ADD COLUMN registration_mode registration_mode_enum NOT NULL DEFAULT 'require_application';
-- generate registration mode value from previous settings
WITH subquery AS (
SELECT
open_registration,
require_application,
CASE WHEN open_registration = FALSE THEN
'closed'::registration_mode_enum
WHEN open_registration = TRUE
AND require_application = TRUE THEN
'require_application'
ELSE
'open'
END
FROM
local_site)
UPDATE
local_site
SET
registration_mode = subquery.case
FROM
subquery;
-- drop old registration settings
ALTER TABLE local_site
DROP COLUMN open_registration;
ALTER TABLE local_site
DROP COLUMN require_application;