mirror of
https://github.com/ksyasuda/aniwrapper.git
synced 2024-10-28 04:44:11 -07:00
update setup sql sripts to backup and update tables automatically
This commit is contained in:
parent
6011e1d5a0
commit
b3f8aa48d3
@ -1,6 +1,44 @@
|
||||
CREATE TABLE file_history (
|
||||
id integer PRIMARY KEY AUTOINCREMENT,
|
||||
directory varchar(200) NOT NULL,
|
||||
filename varchar(200) NOT NULL,
|
||||
watch_date datetime NOT NULL
|
||||
DROP TABLE IF EXISTS temp_file_history;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS temp_file_history (
|
||||
id integer PRIMARY KEY AUTOINCREMENT,
|
||||
directory varchar(200) NOT NULL,
|
||||
filename varchar(200) NOT NULL,
|
||||
watch_date DATETIME NOT NULL,
|
||||
CHECK (LENGTH(directory) > 0),
|
||||
CHECK (LENGTH(filename) > 0),
|
||||
UNIQUE (directory, filename)
|
||||
);
|
||||
|
||||
-- make sure table has been set up at least once
|
||||
CREATE TABLE IF NOT EXISTS file_history (
|
||||
id integer PRIMARY KEY AUTOINCREMENT,
|
||||
directory varchar(200) NOT NULL,
|
||||
filename varchar(200) NOT NULL,
|
||||
watch_date DATETIME NOT NULL,
|
||||
CHECK (LENGTH(directory) > 0),
|
||||
CHECK (LENGTH(filename) > 0),
|
||||
UNIQUE (directory, filename)
|
||||
);
|
||||
|
||||
|
||||
INSERT OR IGNORE INTO temp_file_history
|
||||
SELECT * FROM file_history;
|
||||
|
||||
DROP TABLE file_history;
|
||||
|
||||
CREATE TABLE file_history (
|
||||
id integer PRIMARY KEY AUTOINCREMENT,
|
||||
directory varchar(200) NOT NULL,
|
||||
filename varchar(200) NOT NULL,
|
||||
watch_date DATETIME NOT NULL,
|
||||
CHECK (LENGTH(directory) > 0),
|
||||
CHECK (LENGTH(filename) > 0),
|
||||
UNIQUE (directory, filename)
|
||||
);
|
||||
CREATE UNIQUE INDEX dir_filename_idx ON file_history(directory, filename);
|
||||
|
||||
INSERT INTO file_history
|
||||
SELECT * FROM temp_file_history;
|
||||
|
||||
DROP TABLE temp_file_history;
|
||||
|
@ -1,6 +1,38 @@
|
||||
CREATE TABLE search_history (
|
||||
DROP TABLE IF EXISTS temp_search_history;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS temp_search_history (
|
||||
id integer PRIMARY KEY AUTOINCREMENT,
|
||||
anime_name varchar(200),
|
||||
search_date datetime NOT NULL
|
||||
anime_name varchar(200) NOT NULL,
|
||||
search_date DATETIME NOT NULL,
|
||||
CHECK (LENGTH(anime_name) > 0),
|
||||
UNIQUE (anime_name, search_date)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS search_history (
|
||||
id integer PRIMARY KEY AUTOINCREMENT,
|
||||
anime_name varchar(200) NOT NULL,
|
||||
search_date DATETIME NOT NULL,
|
||||
CHECK (LENGTH(anime_name) > 0),
|
||||
UNIQUE (anime_name, search_date)
|
||||
);
|
||||
|
||||
INSERT OR IGNORE INTO temp_search_history
|
||||
SELECT * FROM search_history;
|
||||
|
||||
DROP TABLE IF EXISTS search_history;
|
||||
|
||||
CREATE TABLE search_history (
|
||||
id integer PRIMARY KEY AUTOINCREMENT,
|
||||
anime_name varchar(200) NOT NULL,
|
||||
search_date DATETIME NOT NULL,
|
||||
CHECK (LENGTH(anime_name) > 0),
|
||||
UNIQUE (anime_name, search_date)
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX anime_search_idx ON search_history (anime_name, search_date);
|
||||
|
||||
INSERT INTO search_history
|
||||
SELECT * FROM temp_search_history;
|
||||
|
||||
DROP TABLE temp_search_history;
|
||||
|
||||
|
@ -1,7 +1,41 @@
|
||||
CREATE TABLE watch_history (
|
||||
id integer PRIMARY KEY AUTOINCREMENT,
|
||||
anime_name varchar(200) NOT NULL,
|
||||
episode_number integer NOT NULL,
|
||||
watch_date datetime NOT NULL
|
||||
DROP TABLE IF EXISTS temp_watch_history;
|
||||
CREATE TABLE temp_watch_history (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
anime_name VARCHAR(200) NOT NULL,
|
||||
episode_number INTEGER NOT NULL,
|
||||
watch_date DATETIME NOT NULL,
|
||||
CHECK(LENGTH(anime_name) > 0),
|
||||
CHECK(episode_number > 0),
|
||||
UNIQUE(anime_name, episode_number, watch_date)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS watch_history (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
anime_name VARCHAR(200) NOT NULL,
|
||||
episode_number INTEGER NOT NULL,
|
||||
watch_date DATETIME NOT NULL,
|
||||
CHECK(LENGTH(anime_name) > 0),
|
||||
CHECK(episode_number > 0),
|
||||
UNIQUE(anime_name, episode_number, watch_date)
|
||||
);
|
||||
|
||||
INSERT OR IGNORE INTO temp_watch_history
|
||||
SELECT * FROM watch_history;
|
||||
|
||||
DROP TABLE watch_history;
|
||||
|
||||
CREATE TABLE watch_history (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
anime_name VARCHAR(200) NOT NULL,
|
||||
episode_number INTEGER NOT NULL,
|
||||
watch_date DATETIME NOT NULL,
|
||||
CHECK(LENGTH(anime_name) > 0),
|
||||
CHECK(episode_number > 0),
|
||||
UNIQUE(anime_name, episode_number, watch_date)
|
||||
);
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS watch_anime_episode_idx ON watch_history(anime_name, episode_number);
|
||||
|
||||
INSERT INTO watch_history
|
||||
SELECT * FROM temp_watch_history;
|
||||
|
||||
DROP TABLE IF EXISTS temp_watch_history;
|
||||
|
Loading…
Reference in New Issue
Block a user