lemmy/migrations/2022-09-08-102358_site-and-community-languages/up.sql
Nutomic 2ef0f8f5f8
implement language tags for site/community in db and api (#2434)
* implement language tags for site/community in db and api

* add api checks for valid languages

* during db migration, update existing users, sites, communities to have all languages enabled

* init new users/communities with site languages (not all languages)

* federate site/community languages

* fix tests

* when updating site languages, limit community languages to this subset

also, when making a new post and subset of user lang, community lang
contains only one item, use that as post lang

* add tests for actor_language db functions

* include language list in siteview/communityview

* Fix some of the review comments

* Some more review changes

* Add todo about boxed query

* Add default_post_language to GetCommunityResponse
2022-10-06 14:27:58 -04:00

39 lines
1.2 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;
$$;