webfaction and repo.or.cz deployment done
[worddb.git] / migrations / 008_worddb_words_models.py
blob237516fd8ddd27c6839dca5889e4fce0a86c6c8b
1 from dmigrations.mysql import migrations as m
2 import datetime
3 migration = m.Migration(sql_up=["""
4 CREATE TABLE `words_word` (
5 `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
6 `word` varchar(100) NOT NULL,
7 `language` varchar(20) NOT NULL,
8 `forms` longtext NOT NULL,
9 `created_on` datetime NOT NULL,
10 `not_a_word` bool NOT NULL,
11 `not_a_word_marked_on` datetime NULL
12 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
14 """, """
15 CREATE TABLE `words_meaning` (
16 `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
17 `word_id` integer NOT NULL,
18 `meaning` longtext NOT NULL,
19 `usage` longtext NOT NULL,
20 `language` varchar(20) NOT NULL,
21 `pol` varchar(20) NOT NULL,
22 `created_on` datetime NOT NULL,
23 `is_deleted` bool NOT NULL,
24 `deleted_on` datetime NULL
25 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
27 """, """
28 ALTER TABLE `words_meaning` ADD CONSTRAINT word_id_refs_id_36e13b73 FOREIGN KEY (`word_id`) REFERENCES `words_word` (`id`);
29 """, """
30 CREATE TABLE `words_pronunciation` (
31 `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
32 `spelling` varchar(100) NOT NULL,
33 `pronunciation_key` varchar(100) NOT NULL,
34 `created_on` datetime NOT NULL,
35 `is_deleted` bool NOT NULL,
36 `deleted_on` datetime NULL
37 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
39 """, """
40 CREATE TABLE `words_etymology` (
41 `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
42 `word_id` integer NOT NULL,
43 `text` longtext NOT NULL,
44 `language` varchar(20) NOT NULL,
45 UNIQUE (`word_id`, `language`)
46 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
48 """, """
49 ALTER TABLE `words_etymology` ADD CONSTRAINT word_id_refs_id_6367a4d3 FOREIGN KEY (`word_id`) REFERENCES `words_word` (`id`);
50 """, """
51 CREATE TABLE `words_short` (
52 `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
53 `word_id` integer NOT NULL,
54 `text` varchar(50) NOT NULL,
55 `language` varchar(20) NOT NULL,
56 UNIQUE (`word_id`, `language`)
57 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
59 """, """
60 ALTER TABLE `words_short` ADD CONSTRAINT word_id_refs_id_172d9be4 FOREIGN KEY (`word_id`) REFERENCES `words_word` (`id`);
61 """, """
62 CREATE TABLE `words_changesheet` (
63 `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
64 `word_id` integer NOT NULL,
65 `type` varchar(50) NOT NULL,
66 `id_1` integer NULL,
67 `data` longtext NOT NULL,
68 `user_id` integer NOT NULL,
69 `created_on` datetime NOT NULL
70 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
72 """, """
73 ALTER TABLE `words_changesheet` ADD CONSTRAINT word_id_refs_id_6ca3505f FOREIGN KEY (`word_id`) REFERENCES `words_word` (`id`);
74 """, """
75 CREATE TABLE `words_word_synonyms` (
76 `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
77 `from_word_id` integer NOT NULL,
78 `to_word_id` integer NOT NULL,
79 UNIQUE (`from_word_id`, `to_word_id`)
80 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
82 """, """
83 ALTER TABLE `words_word_synonyms` ADD CONSTRAINT from_word_id_refs_id_7b61f267 FOREIGN KEY (`from_word_id`) REFERENCES `words_word` (`id`);
84 """, """
85 ALTER TABLE `words_word_synonyms` ADD CONSTRAINT to_word_id_refs_id_7b61f267 FOREIGN KEY (`to_word_id`) REFERENCES `words_word` (`id`);
86 """, """
87 CREATE TABLE `words_word_thesaurus` (
88 `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
89 `from_word_id` integer NOT NULL,
90 `to_word_id` integer NOT NULL,
91 UNIQUE (`from_word_id`, `to_word_id`)
92 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
94 """, """
95 ALTER TABLE `words_word_thesaurus` ADD CONSTRAINT from_word_id_refs_id_4f11e954 FOREIGN KEY (`from_word_id`) REFERENCES `words_word` (`id`);
96 """, """
97 ALTER TABLE `words_word_thesaurus` ADD CONSTRAINT to_word_id_refs_id_4f11e954 FOREIGN KEY (`to_word_id`) REFERENCES `words_word` (`id`);
98 """, """
99 CREATE TABLE `words_word_antonyms` (
100 `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
101 `from_word_id` integer NOT NULL,
102 `to_word_id` integer NOT NULL,
103 UNIQUE (`from_word_id`, `to_word_id`)
104 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
106 """, """
107 ALTER TABLE `words_word_antonyms` ADD CONSTRAINT from_word_id_refs_id_37cc738 FOREIGN KEY (`from_word_id`) REFERENCES `words_word` (`id`);
108 """, """
109 ALTER TABLE `words_word_antonyms` ADD CONSTRAINT to_word_id_refs_id_37cc738 FOREIGN KEY (`to_word_id`) REFERENCES `words_word` (`id`);
110 """, """
111 CREATE TABLE `words_word_translations` (
112 `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
113 `from_word_id` integer NOT NULL,
114 `to_word_id` integer NOT NULL,
115 UNIQUE (`from_word_id`, `to_word_id`)
116 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
118 """, """
119 ALTER TABLE `words_word_translations` ADD CONSTRAINT from_word_id_refs_id_2ec7430d FOREIGN KEY (`from_word_id`) REFERENCES `words_word` (`id`);
120 """, """
121 ALTER TABLE `words_word_translations` ADD CONSTRAINT to_word_id_refs_id_2ec7430d FOREIGN KEY (`to_word_id`) REFERENCES `words_word` (`id`);
122 """, """
123 CREATE TABLE `words_word_rhymes` (
124 `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
125 `from_word_id` integer NOT NULL,
126 `to_word_id` integer NOT NULL,
127 UNIQUE (`from_word_id`, `to_word_id`)
128 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
130 """, """
131 ALTER TABLE `words_word_rhymes` ADD CONSTRAINT from_word_id_refs_id_3eb1d69 FOREIGN KEY (`from_word_id`) REFERENCES `words_word` (`id`);
132 """, """
133 ALTER TABLE `words_word_rhymes` ADD CONSTRAINT to_word_id_refs_id_3eb1d69 FOREIGN KEY (`to_word_id`) REFERENCES `words_word` (`id`);
134 """, """
135 CREATE TABLE `words_word_relateds` (
136 `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
137 `from_word_id` integer NOT NULL,
138 `to_word_id` integer NOT NULL,
139 UNIQUE (`from_word_id`, `to_word_id`)
140 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
142 """, """
143 ALTER TABLE `words_word_relateds` ADD CONSTRAINT from_word_id_refs_id_1d5c3a5 FOREIGN KEY (`from_word_id`) REFERENCES `words_word` (`id`);
144 """, """
145 ALTER TABLE `words_word_relateds` ADD CONSTRAINT to_word_id_refs_id_1d5c3a5 FOREIGN KEY (`to_word_id`) REFERENCES `words_word` (`id`);
146 """, """
147 -- The following references should be added but depend on non-existent tables:
148 """, """
149 -- ALTER TABLE `words_changesheet` ADD CONSTRAINT user_id_refs_id_19c4841e FOREIGN KEY (`user_id`) REFERENCES `auth_user` (`id`);
150 """], sql_down=["""
151 DROP TABLE `words_word_relateds`;
152 """, """
153 DROP TABLE `words_word_rhymes`;
154 """, """
155 DROP TABLE `words_word_translations`;
156 """, """
157 DROP TABLE `words_word_antonyms`;
158 """, """
159 DROP TABLE `words_word_thesaurus`;
160 """, """
161 DROP TABLE `words_word_synonyms`;
162 """, """
163 DROP TABLE `words_changesheet`;
164 """, """
165 DROP TABLE `words_short`;
166 """, """
167 DROP TABLE `words_etymology`;
168 """, """
169 DROP TABLE `words_pronunciation`;
170 """, """
171 DROP TABLE `words_meaning`;
172 """, """
173 DROP TABLE `words_word`;
174 """])