mirror of
https://github.com/Eggbertx/gochan.git
synced 2025-08-19 08:26:23 -07:00
Add spoilered column to threads table and improve initdb scripts to remove comments and properly get sql directory relative to script directory
This commit is contained in:
parent
556de0d4ac
commit
01faaa992f
5 changed files with 30 additions and 42 deletions
|
@ -4,7 +4,6 @@
|
|||
-- Versioning numbering goes by whole numbers. Upgrade script migrate existing databases between versions
|
||||
-- Foreign and unique constraints must be named so they can be dropped.
|
||||
-- MySQL requires constraint names to be unique globally, hence the long constraint names.
|
||||
-- Database version: 1
|
||||
|
||||
CREATE TABLE DBPREFIXdatabase_version(
|
||||
component VARCHAR(40) NOT NULL PRIMARY KEY,
|
||||
|
@ -56,6 +55,7 @@ CREATE TABLE DBPREFIXthreads(
|
|||
stickied BOOL NOT NULL DEFAULT FALSE,
|
||||
anchored BOOL NOT NULL DEFAULT FALSE,
|
||||
cyclical BOOL NOT NULL DEFAULT FALSE,
|
||||
spoilered BOOL NOT NULL DEFAULT FALSE,
|
||||
last_bump TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
deleted_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
is_deleted BOOL NOT NULL DEFAULT FALSE,
|
||||
|
|
|
@ -1,11 +1,3 @@
|
|||
-- Gochan master template for new database script
|
||||
-- Contains macros in the form [curlybrace open]macro text[curlybrace close]
|
||||
-- Macros are substituted by build_initdb.py to the supported database files. Must not contain extra spaces
|
||||
-- Versioning numbering goes by whole numbers. Upgrade script migrate existing databases between versions
|
||||
-- Foreign and unique constraints must be named so they can be dropped.
|
||||
-- MySQL requires constraint names to be unique globally, hence the long constraint names.
|
||||
-- Database version: 1
|
||||
|
||||
CREATE TABLE DBPREFIXdatabase_version(
|
||||
component VARCHAR(40) NOT NULL PRIMARY KEY,
|
||||
version INT NOT NULL
|
||||
|
@ -56,6 +48,7 @@ CREATE TABLE DBPREFIXthreads(
|
|||
stickied BOOL NOT NULL DEFAULT FALSE,
|
||||
anchored BOOL NOT NULL DEFAULT FALSE,
|
||||
cyclical BOOL NOT NULL DEFAULT FALSE,
|
||||
spoilered BOOL NOT NULL DEFAULT FALSE,
|
||||
last_bump TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
deleted_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
is_deleted BOOL NOT NULL DEFAULT FALSE,
|
||||
|
@ -293,6 +286,5 @@ CREATE TABLE DBPREFIXfilter_hits(
|
|||
ON DELETE CASCADE
|
||||
);
|
||||
|
||||
|
||||
INSERT INTO DBPREFIXdatabase_version(component, version)
|
||||
VALUES('gochan', 4);
|
||||
|
|
|
@ -1,11 +1,3 @@
|
|||
-- Gochan master template for new database script
|
||||
-- Contains macros in the form [curlybrace open]macro text[curlybrace close]
|
||||
-- Macros are substituted by build_initdb.py to the supported database files. Must not contain extra spaces
|
||||
-- Versioning numbering goes by whole numbers. Upgrade script migrate existing databases between versions
|
||||
-- Foreign and unique constraints must be named so they can be dropped.
|
||||
-- MySQL requires constraint names to be unique globally, hence the long constraint names.
|
||||
-- Database version: 1
|
||||
|
||||
CREATE TABLE DBPREFIXdatabase_version(
|
||||
component VARCHAR(40) NOT NULL PRIMARY KEY,
|
||||
version INT NOT NULL
|
||||
|
@ -56,6 +48,7 @@ CREATE TABLE DBPREFIXthreads(
|
|||
stickied BOOL NOT NULL DEFAULT FALSE,
|
||||
anchored BOOL NOT NULL DEFAULT FALSE,
|
||||
cyclical BOOL NOT NULL DEFAULT FALSE,
|
||||
spoilered BOOL NOT NULL DEFAULT FALSE,
|
||||
last_bump TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
deleted_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
is_deleted BOOL NOT NULL DEFAULT FALSE,
|
||||
|
@ -293,6 +286,5 @@ CREATE TABLE DBPREFIXfilter_hits(
|
|||
ON DELETE CASCADE
|
||||
);
|
||||
|
||||
|
||||
INSERT INTO DBPREFIXdatabase_version(component, version)
|
||||
VALUES('gochan', 4);
|
||||
|
|
|
@ -1,11 +1,3 @@
|
|||
-- Gochan master template for new database script
|
||||
-- Contains macros in the form [curlybrace open]macro text[curlybrace close]
|
||||
-- Macros are substituted by build_initdb.py to the supported database files. Must not contain extra spaces
|
||||
-- Versioning numbering goes by whole numbers. Upgrade script migrate existing databases between versions
|
||||
-- Foreign and unique constraints must be named so they can be dropped.
|
||||
-- MySQL requires constraint names to be unique globally, hence the long constraint names.
|
||||
-- Database version: 1
|
||||
|
||||
CREATE TABLE DBPREFIXdatabase_version(
|
||||
component VARCHAR(40) NOT NULL PRIMARY KEY,
|
||||
version INT NOT NULL
|
||||
|
@ -56,6 +48,7 @@ CREATE TABLE DBPREFIXthreads(
|
|||
stickied BOOL NOT NULL DEFAULT FALSE,
|
||||
anchored BOOL NOT NULL DEFAULT FALSE,
|
||||
cyclical BOOL NOT NULL DEFAULT FALSE,
|
||||
spoilered BOOL NOT NULL DEFAULT FALSE,
|
||||
last_bump TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
deleted_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
is_deleted BOOL NOT NULL DEFAULT FALSE,
|
||||
|
@ -293,6 +286,5 @@ CREATE TABLE DBPREFIXfilter_hits(
|
|||
ON DELETE CASCADE
|
||||
);
|
||||
|
||||
|
||||
INSERT INTO DBPREFIXdatabase_version(component, version)
|
||||
VALUES('gochan', 4);
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
import argparse
|
||||
from os import path
|
||||
import re
|
||||
|
||||
class macro():
|
||||
""" Use a macro like this {exact macro name} """
|
||||
|
@ -38,6 +39,17 @@ def compileOutIfs(text, flag):
|
|||
return newText
|
||||
|
||||
|
||||
def compileOutComments(text:str):
|
||||
lines = text.splitlines()
|
||||
out = ""
|
||||
for line in lines:
|
||||
if line != "" and line is not None:
|
||||
out += re.sub(r"--.*$", "", line) + "\n"
|
||||
if line.endswith(";"):
|
||||
out += "\n"
|
||||
return out.strip() + "\n"
|
||||
|
||||
|
||||
def hasError(text):
|
||||
if '{' in text or '}' in text:
|
||||
return True
|
||||
|
@ -45,14 +57,14 @@ def hasError(text):
|
|||
|
||||
|
||||
def dofile(filestart):
|
||||
print("building " + filestart + "master.sql file")
|
||||
print(f"processing {filestart}master.sql file")
|
||||
masterfile = ""
|
||||
with open(filestart + "master.sql", 'r') as masterfileIn: # skipcq: PTC-W6004
|
||||
with open(f"{filestart}master.sql", 'r') as masterfileIn: # skipcq: PTC-W6004
|
||||
masterfile = masterfileIn.read()
|
||||
|
||||
postgresProcessed = compileOutIfs(masterfile, "POSTGRES")
|
||||
mysqlProcessed = compileOutIfs(masterfile, "MYSQL")
|
||||
sqlite3Processed = compileOutIfs(masterfile, "SQLITE3")
|
||||
postgresProcessed = compileOutComments(compileOutIfs(masterfile, "POSTGRES"))
|
||||
mysqlProcessed = compileOutComments(compileOutIfs(masterfile, "MYSQL"))
|
||||
sqlite3Processed = compileOutComments(compileOutIfs(masterfile, "SQLITE3"))
|
||||
|
||||
for item in macros:
|
||||
macroCode = "{" + item.macroname + "}"
|
||||
|
@ -60,30 +72,30 @@ def dofile(filestart):
|
|||
mysqlProcessed = mysqlProcessed.replace(macroCode, item.mysql)
|
||||
sqlite3Processed = sqlite3Processed.replace(macroCode, item.sqlite3)
|
||||
|
||||
error = hasError(postgresProcessed)
|
||||
error = error or hasError(mysqlProcessed)
|
||||
if hasError(postgresProcessed) or hasError(mysqlProcessed):
|
||||
raise Exception("Files still contain curly braces after macro processing")
|
||||
|
||||
print(f"building {filestart}postgres.sql")
|
||||
with open(filestart + "postgres.sql", 'w') as i:
|
||||
i.write(postgresProcessed)
|
||||
|
||||
print(f"building {filestart}mysql.sql")
|
||||
with open(filestart + "sqlite3.sql", 'w') as i:
|
||||
i.write(sqlite3Processed)
|
||||
|
||||
print(f"building {filestart}sqlite3.sql")
|
||||
with open(filestart + "mysql.sql", 'w') as i:
|
||||
i.write(mysqlProcessed)
|
||||
|
||||
if error:
|
||||
input(
|
||||
"Error processing macros, files still contain curly braces (might be in comments?)\n",
|
||||
"press any key to continue")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sql_dir = path.normpath(path.join(path.dirname(path.abspath(__file__)), "..", "sql"))
|
||||
|
||||
parser = argparse.ArgumentParser(description="gochan build script")
|
||||
dofile(path.join("..", "sql", "initdb_"))
|
||||
dofile(path.join(sql_dir, "initdb_"))
|
||||
parser.add_argument("--preapril2020",
|
||||
action="store_true",
|
||||
help="Also build the legacy (pre-April 2020 migration) database schema used for testing gochan-migrate.")
|
||||
args = parser.parse_args()
|
||||
if args.preapril2020:
|
||||
dofile(path.join("..", "sql", "preapril2020migration", "oldDBMigration_"))
|
||||
dofile(path.join(sql_dir, "preapril2020migration", "oldDBMigration_"))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue