Refactor [Tag] table: remove lang column. Remove [Tag] when no more recipe uses it.
This commit is contained in:
parent
c16c0987c8
commit
92fa462ae2
1 changed files with 18 additions and 4 deletions
|
|
@ -111,15 +111,17 @@ CREATE TABLE [Image] (
|
|||
CREATE TABLE [Tag] (
|
||||
[id] INTEGER PRIMARY KEY,
|
||||
[name] TEXT NOT NULL,
|
||||
[lang] TEXT NOT NULL DEFAULT 'en',
|
||||
|
||||
-- Not needed, the lang is defined by the recipes linked to it
|
||||
-- (more than one language can be associaded to a tag).
|
||||
-- [lang] TEXT NOT NULL DEFAULT 'en',
|
||||
|
||||
CHECK (
|
||||
length([name]) <= 31 AND
|
||||
length([lang]) = 2
|
||||
length([name]) <= 31
|
||||
)
|
||||
) STRICT;
|
||||
|
||||
CREATE UNIQUE INDEX [Tag_name_lang_index] ON [Tag]([name], [lang]);
|
||||
CREATE UNIQUE INDEX [Tag_name_index] ON [Tag]([name]);
|
||||
|
||||
CREATE TABLE [RecipeTag] (
|
||||
[id] INTEGER PRIMARY KEY,
|
||||
|
|
@ -133,6 +135,18 @@ CREATE TABLE [RecipeTag] (
|
|||
FOREIGN KEY([tag_id]) REFERENCES [Tag]([id]) ON DELETE CASCADE
|
||||
) STRICT;
|
||||
|
||||
CREATE INDEX [RecipeTag_tag_id_index] ON [RecipeTag]([tag_id]);
|
||||
|
||||
-- Delete all tags without references.
|
||||
CREATE TRIGGER [RecipeTag_trigger_delete]
|
||||
AFTER DELETE
|
||||
ON [RecipeTag]
|
||||
BEGIN
|
||||
DELETE FROM [Tag] WHERE
|
||||
[id] = OLD.[tag_id] AND
|
||||
(SELECT COUNT(*) = 0 FROM [RecipeTag] WHERE [tag_id] = OLD.[tag_id]);
|
||||
END;
|
||||
|
||||
CREATE TABLE [Group] (
|
||||
[id] INTEGER PRIMARY KEY,
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue