-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sqlite): created first migration script to initialized database
- Loading branch information
Showing
5 changed files
with
87 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,3 +33,6 @@ assets | |
# Nix | ||
result | ||
api | ||
|
||
# Sqlit | ||
*.sqlite |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
drop table if exists jokes; | ||
drop trigger if exists joke_add_event_trigger; | ||
drop trigger if exists joke_update_event_trigger; | ||
drop table if exists jokes_audit; | ||
drop table if exists jokes_audit; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
create table jokes | ||
( | ||
id integer primary key autoincrement, | ||
question text, | ||
answer text not null, | ||
type text not null, | ||
category text not null, | ||
userID text, | ||
guildID text | ||
); | ||
|
||
create index jokes_index on jokes (id, guildID); | ||
|
||
create table jokes_audit | ||
( | ||
id primary key, | ||
status text default 'CREATED', | ||
joke_id integer not null, | ||
question text, | ||
answer text not null, | ||
type text not null, | ||
category text not null, | ||
userID text, | ||
guildID text | ||
); | ||
|
||
create trigger joke_add_event_trigger | ||
after insert | ||
on jokes | ||
begin | ||
insert | ||
into jokes_audit(joke_id, question, answer, type, category, userID, guildID) | ||
values (new.id, new.question, new.answer, new.type, new.category, new.userID, new.guildID); | ||
end; | ||
|
||
create trigger joke_update_event_trigger | ||
after update | ||
on jokes | ||
begin | ||
insert | ||
into jokes_audit(status, joke_id, question, answer, type, category, userID, guildID) | ||
values ('UPDATED', new.id, new.question, new.answer, new.type, | ||
new.category, | ||
new.userID, new.guildID); | ||
end; | ||
|
||
create trigger joke_delete_event_trigger | ||
before delete | ||
on jokes | ||
begin | ||
insert | ||
into jokes_audit(status, joke_id, question, answer, type, category, userID, guildID) | ||
values ('DELETE', old.id, old.question, old.answer, old.type, | ||
old.category, | ||
old.userID, old.guildID); | ||
end; | ||
|
||
create table admins | ||
( | ||
id primary key, | ||
name text unique not null | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters