-
-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #156 from hkalexling/dev
v0.20.0
- Loading branch information
Showing
28 changed files
with
746 additions
and
78 deletions.
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
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
This file was deleted.
Oops, something went wrong.
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,50 @@ | ||
class IDSignature < MG::Base | ||
def up : String | ||
<<-SQL | ||
ALTER TABLE ids ADD COLUMN signature TEXT; | ||
SQL | ||
end | ||
|
||
def down : String | ||
<<-SQL | ||
-- remove signature column from ids | ||
ALTER TABLE ids RENAME TO tmp; | ||
CREATE TABLE ids ( | ||
path TEXT NOT NULL, | ||
id TEXT NOT NULL | ||
); | ||
INSERT INTO ids | ||
SELECT path, id | ||
FROM tmp; | ||
DROP TABLE tmp; | ||
-- recreate the indices | ||
CREATE UNIQUE INDEX path_idx ON ids (path); | ||
CREATE UNIQUE INDEX id_idx ON ids (id); | ||
-- recreate the foreign key constraint on thumbnails | ||
ALTER TABLE thumbnails RENAME TO tmp; | ||
CREATE TABLE thumbnails ( | ||
id TEXT NOT NULL, | ||
data BLOB NOT NULL, | ||
filename TEXT NOT NULL, | ||
mime TEXT NOT NULL, | ||
size INTEGER NOT NULL, | ||
FOREIGN KEY (id) REFERENCES ids (id) | ||
ON UPDATE CASCADE | ||
ON DELETE CASCADE | ||
); | ||
INSERT INTO thumbnails | ||
SELECT * FROM tmp; | ||
DROP TABLE tmp; | ||
CREATE UNIQUE INDEX tn_index ON thumbnails (id); | ||
SQL | ||
end | ||
end |
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,33 @@ | ||
class RelativePath < MG::Base | ||
def up : String | ||
base = Config.current.library_path | ||
# Escape single quotes in case the path contains them, and remove the | ||
# trailing slash (this is a mistake, fixed in DB version 10) | ||
base = base.gsub("'", "''").rstrip "/" | ||
|
||
<<-SQL | ||
-- update the path column in ids to relative paths | ||
UPDATE ids | ||
SET path = REPLACE(path, '#{base}', ''); | ||
-- update the path column in titles to relative paths | ||
UPDATE titles | ||
SET path = REPLACE(path, '#{base}', ''); | ||
SQL | ||
end | ||
|
||
def down : String | ||
base = Config.current.library_path | ||
base = base.gsub("'", "''").rstrip "/" | ||
|
||
<<-SQL | ||
-- update the path column in ids to absolute paths | ||
UPDATE ids | ||
SET path = '#{base}' || path; | ||
-- update the path column in titles to absolute paths | ||
UPDATE titles | ||
SET path = '#{base}' || path; | ||
SQL | ||
end | ||
end |
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,31 @@ | ||
# In DB version 8, we replaced the absolute paths in DB with relative paths, | ||
# but we mistakenly left the starting slashes. This migration removes them. | ||
class RelativePathFix < MG::Base | ||
def up : String | ||
<<-SQL | ||
-- remove leading slashes from the paths in ids | ||
UPDATE ids | ||
SET path = SUBSTR(path, 2, LENGTH(path) - 1) | ||
WHERE path LIKE '/%'; | ||
-- remove leading slashes from the paths in titles | ||
UPDATE titles | ||
SET path = SUBSTR(path, 2, LENGTH(path) - 1) | ||
WHERE path LIKE '/%'; | ||
SQL | ||
end | ||
|
||
def down : String | ||
<<-SQL | ||
-- add leading slashes to paths in ids | ||
UPDATE ids | ||
SET path = '/' || path | ||
WHERE path NOT LIKE '/%'; | ||
-- add leading slashes to paths in titles | ||
UPDATE titles | ||
SET path = '/' || path | ||
WHERE path NOT LIKE '/%'; | ||
SQL | ||
end | ||
end |
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,94 @@ | ||
class UnavailableIDs < MG::Base | ||
def up : String | ||
<<-SQL | ||
-- add unavailable column to ids | ||
ALTER TABLE ids ADD COLUMN unavailable INTEGER NOT NULL DEFAULT 0; | ||
-- add unavailable column to titles | ||
ALTER TABLE titles ADD COLUMN unavailable INTEGER NOT NULL DEFAULT 0; | ||
SQL | ||
end | ||
|
||
def down : String | ||
<<-SQL | ||
-- remove unavailable column from ids | ||
ALTER TABLE ids RENAME TO tmp; | ||
CREATE TABLE ids ( | ||
path TEXT NOT NULL, | ||
id TEXT NOT NULL, | ||
signature TEXT | ||
); | ||
INSERT INTO ids | ||
SELECT path, id, signature | ||
FROM tmp; | ||
DROP TABLE tmp; | ||
-- recreate the indices | ||
CREATE UNIQUE INDEX path_idx ON ids (path); | ||
CREATE UNIQUE INDEX id_idx ON ids (id); | ||
-- recreate the foreign key constraint on thumbnails | ||
ALTER TABLE thumbnails RENAME TO tmp; | ||
CREATE TABLE thumbnails ( | ||
id TEXT NOT NULL, | ||
data BLOB NOT NULL, | ||
filename TEXT NOT NULL, | ||
mime TEXT NOT NULL, | ||
size INTEGER NOT NULL, | ||
FOREIGN KEY (id) REFERENCES ids (id) | ||
ON UPDATE CASCADE | ||
ON DELETE CASCADE | ||
); | ||
INSERT INTO thumbnails | ||
SELECT * FROM tmp; | ||
DROP TABLE tmp; | ||
CREATE UNIQUE INDEX tn_index ON thumbnails (id); | ||
-- remove unavailable column from titles | ||
ALTER TABLE titles RENAME TO tmp; | ||
CREATE TABLE titles ( | ||
id TEXT NOT NULL, | ||
path TEXT NOT NULL, | ||
signature TEXT | ||
); | ||
INSERT INTO titles | ||
SELECT path, id, signature | ||
FROM tmp; | ||
DROP TABLE tmp; | ||
-- recreate the indices | ||
CREATE UNIQUE INDEX titles_id_idx on titles (id); | ||
CREATE UNIQUE INDEX titles_path_idx on titles (path); | ||
-- recreate the foreign key constraint on tags | ||
ALTER TABLE tags RENAME TO tmp; | ||
CREATE TABLE tags ( | ||
id TEXT NOT NULL, | ||
tag TEXT NOT NULL, | ||
UNIQUE (id, tag), | ||
FOREIGN KEY (id) REFERENCES titles (id) | ||
ON UPDATE CASCADE | ||
ON DELETE CASCADE | ||
); | ||
INSERT INTO tags | ||
SELECT * FROM tmp; | ||
DROP TABLE tmp; | ||
CREATE INDEX tags_id_idx ON tags (id); | ||
CREATE INDEX tags_tag_idx ON tags (tag); | ||
SQL | ||
end | ||
end |
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
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,60 @@ | ||
const component = () => { | ||
return { | ||
empty: true, | ||
titles: [], | ||
entries: [], | ||
loading: true, | ||
|
||
load() { | ||
this.loading = true; | ||
this.request('GET', `${base_url}api/admin/titles/missing`, data => { | ||
this.titles = data.titles; | ||
this.request('GET', `${base_url}api/admin/entries/missing`, data => { | ||
this.entries = data.entries; | ||
this.loading = false; | ||
this.empty = this.entries.length === 0 && this.titles.length === 0; | ||
}); | ||
}); | ||
}, | ||
rm(event) { | ||
const rawID = event.currentTarget.closest('tr').id; | ||
const [type, id] = rawID.split('-'); | ||
const url = `${base_url}api/admin/${type === 'title' ? 'titles' : 'entries'}/missing/${id}`; | ||
this.request('DELETE', url, () => { | ||
this.load(); | ||
}); | ||
}, | ||
rmAll() { | ||
UIkit.modal.confirm('Are you sure? All metadata associated with these items, including their tags and thumbnails, will be deleted from the database.', { | ||
labels: { | ||
ok: 'Yes, delete them', | ||
cancel: 'Cancel' | ||
} | ||
}).then(() => { | ||
this.request('DELETE', `${base_url}api/admin/titles/missing`, () => { | ||
this.request('DELETE', `${base_url}api/admin/entries/missing`, () => { | ||
this.load(); | ||
}); | ||
}); | ||
}); | ||
}, | ||
request(method, url, cb) { | ||
console.log(url); | ||
$.ajax({ | ||
type: method, | ||
url: url, | ||
contentType: 'application/json' | ||
}) | ||
.done(data => { | ||
if (data.error) { | ||
alert('danger', `Failed to ${method} ${url}. Error: ${data.error}`); | ||
return; | ||
} | ||
if (cb) cb(data); | ||
}) | ||
.fail((jqXHR, status) => { | ||
alert('danger', `Failed to ${method} ${url}. Error: [${jqXHR.status}] ${jqXHR.statusText}`); | ||
}); | ||
} | ||
}; | ||
}; |
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
name: mango | ||
version: 0.19.1 | ||
version: 0.20.0 | ||
|
||
authors: | ||
- Alex Ling <[email protected]> | ||
|
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
Oops, something went wrong.