1 ALTER TABLE users ADD COLUMN theme_id INT;
2 --ALTER TABLE users ALTER COLUMN theme_id SET DEFAULT NOT NULL 1;
3 --UPDATE users SET theme_id=1
4 -- WHERE NOT EXISTS (select user_theme FROM theme_prefs WHERE user_id=users.user_id);
5 UPDATE users SET theme_id=
6 (select user_theme FROM theme_prefs WHERE user_id=users.user_id)
7 WHERE EXISTS (select user_theme FROM theme_prefs WHERE user_id=users.user_id);
9 -- If there is no theme_id=1 in the themes table, we could have a problem
11 UPDATE users SET theme_id=(SELECT min(theme_id) FROM themes WHERE enabled=true LIMIT 1)
12 WHERE theme_id IS NULL;
13 ALTER TABLE users ADD CONSTRAINT users_themeid
14 FOREIGN KEY (theme_id) REFERENCES themes(theme_id) MATCH FULL;
15 ALTER TABLE users ADD CONSTRAINT users_ccode
16 FOREIGN KEY (ccode) REFERENCES country_code(ccode) MATCH FULL;
17 DROP TABLE theme_prefs;