Submission uploads (lib.uploadRequest.processFile) generate an error: null value in column active violates not-null constraint. This sets a default value on this column of false and columns in the visits table to zero which also have not-null constraints, ensuring errors like these are prevented

This commit is contained in:
endangered 2019-11-25 06:15:28 +09:30
parent defaa2ae0b
commit 9ea77c095f

View file

@ -135,11 +135,22 @@ func RO(db DB) DB {
}
const createSQL = `
-- Visits default values
ALTER TABLE visits ALTER COLUMN downloads SET DEFAULT 0 ;
ALTER TABLE visits ALTER COLUMN views SET DEFAULT 0 ;
-- Books default values
ALTER TABLE books ALTER COLUMN active SET DEFAULT false ;
-- Books column indexes
CREATE INDEX IF NOT EXISTS books_lang_idx ON books (lang);
CREATE INDEX IF NOT EXISTS books_isbn_idx ON books (isbn);
CREATE INDEX IF NOT EXISTS books_active_idx ON books (active);
-- Books trigram indexes
CREATE INDEX IF NOT EXISTS books_title_idx ON books USING GIN (title gin_trgm_ops);
CREATE INDEX IF NOT EXISTS books_contributor_idx ON books USING GIN (contributor gin_trgm_ops);