mirror of
https://github.com/LemmyNet/lemmy
synced 2024-11-23 04:53:06 +00:00
be1389420b
* 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.
62 lines
1.5 KiB
SQL
62 lines
1.5 KiB
SQL
CREATE TABLE site_language (
|
|
id serial PRIMARY KEY,
|
|
site_id int REFERENCES site ON UPDATE CASCADE ON DELETE CASCADE NOT NULL,
|
|
language_id int REFERENCES
|
|
LANGUAGE ON
|
|
UPDATE CASCADE ON DELETE CASCADE NOT NULL,
|
|
UNIQUE (site_id, language_id)
|
|
);
|
|
|
|
CREATE TABLE community_language (
|
|
id serial PRIMARY KEY,
|
|
community_id int REFERENCES community ON UPDATE CASCADE ON DELETE CASCADE NOT NULL,
|
|
language_id int REFERENCES
|
|
LANGUAGE ON
|
|
UPDATE CASCADE ON DELETE CASCADE NOT NULL,
|
|
UNIQUE (community_id, language_id)
|
|
);
|
|
|
|
-- update existing users, sites and communities to have all languages enabled
|
|
DO $$
|
|
DECLARE
|
|
xid integer;
|
|
BEGIN
|
|
FOR xid IN
|
|
SELECT
|
|
id
|
|
FROM
|
|
local_user LOOP
|
|
INSERT INTO local_user_language (local_user_id, language_id) (
|
|
SELECT
|
|
xid,
|
|
language.id AS lid
|
|
FROM
|
|
LANGUAGE);
|
|
END LOOP;
|
|
FOR xid IN
|
|
SELECT
|
|
id
|
|
FROM
|
|
site LOOP
|
|
INSERT INTO site_language (site_id, language_id) (
|
|
SELECT
|
|
xid,
|
|
language.id AS lid
|
|
FROM
|
|
LANGUAGE);
|
|
END LOOP;
|
|
FOR xid IN
|
|
SELECT
|
|
id
|
|
FROM
|
|
community LOOP
|
|
INSERT INTO community_language (community_id, language_id) (
|
|
SELECT
|
|
xid,
|
|
language.id AS lid
|
|
FROM
|
|
LANGUAGE);
|
|
END LOOP;
|
|
END;
|
|
$$;
|
|
|