mirror of
https://github.com/Eggbertx/gochan.git
synced 2025-08-02 02:36:24 -07:00
Add #if flag markers in sql macro script
Made some changes
This commit is contained in:
parent
72eb7e5467
commit
3905ec1393
4 changed files with 67 additions and 35 deletions
|
@ -15,14 +15,30 @@ macros = [
|
|||
macro("drop fk", "DROP CONSTRAINT", "DROP FOREIGN KEY")
|
||||
]
|
||||
|
||||
def compileOutIfs(text, flag):
|
||||
lines = text.splitlines()
|
||||
newText = ""
|
||||
compile = True
|
||||
for i in lines:
|
||||
if "#IF" in i:
|
||||
if flag in i:
|
||||
compile = True
|
||||
else:
|
||||
compile = False
|
||||
elif "#ENDIF" in i:
|
||||
compile = True
|
||||
elif compile:
|
||||
newText += i + "\n"
|
||||
return newText
|
||||
|
||||
def dofile(filestart):
|
||||
print("building " + filestart + " sql file")
|
||||
masterfileIn = open(filestart + "master.sql", 'r')
|
||||
masterfile = masterfileIn.read()
|
||||
masterfileIn.close()
|
||||
|
||||
postgresProcessed = masterfile
|
||||
mysqlProcessed = masterfile
|
||||
postgresProcessed = compileOutIfs(masterfile, "POSTGRES")
|
||||
mysqlProcessed = compileOutIfs(masterfile, "MYSQL")
|
||||
|
||||
for item in macros:
|
||||
macroCode = "{" + item.macroname + "}"
|
||||
|
|
|
@ -69,22 +69,43 @@ ALTER TABLE DBPREFIXthreads ADD oldpostid int;
|
|||
ALTER TABLE DBPREFIXposts ADD oldselfid int;
|
||||
ALTER TABLE DBPREFIXposts ADD oldparentid int;
|
||||
ALTER TABLE DBPREFIXposts ADD oldboardid int;
|
||||
ALTER TABLE DBPREFIXposts {drop fk} thread_id;
|
||||
ALTER TABLE DBPREFIXposts {drop fk} posts_thread_id_fk;
|
||||
ALTER TABLE DBPREFIXfiles ADD oldpostid int;
|
||||
ALTER TABLE DBPREFIXfiles ADD oldboardid int;
|
||||
ALTER TABLE DBPREFIXfiles {drop fk} post_id;
|
||||
ALTER TABLE DBPREFIXfiles {drop fk} files_post_id_fk;
|
||||
#IF POSTGRES
|
||||
-- Drops not null constraint
|
||||
ALTER TABLE DBPREFIXposts ALTER COLUMN thread_id DROP NOT NULL;
|
||||
ALTER TABLE DBPREFIXfiles ALTER COLUMN post_id DROP NOT NULL;
|
||||
#ENDIF
|
||||
#IF MYSQL
|
||||
-- Drops not null constraint
|
||||
ALTER TABLE DBPREFIXposts MODIFY thread_id {fk to serial};
|
||||
ALTER TABLE DBPREFIXfiles MODIFY post_id {fk to serial};
|
||||
#ENDIF
|
||||
|
||||
INSERT INTO DBPREFIXthreads(board_id, locked, stickied, anchored, last_bump, is_deleted, deleted_at, oldpostid)
|
||||
SELECT boardid, locked, stickied, autosage, bumped, deleted_timestamp > '2000-01-01', deleted_timestamp, id FROM DBPREFIXposts_old WHERE parentid = 0;
|
||||
|
||||
INSERT INTO DBPREFIXposts(is_top_post, ip, created_on, name, tripcode, is_role_signature, email, subject, message, message_raw, password, deleted_at, is_deleted, oldparentid, oldboardid)
|
||||
INSERT INTO DBPREFIXposts(is_top_post, ip, created_on, name, tripcode, is_role_signature, email, subject, message, message_raw, password, deleted_at, is_deleted, oldparentid, oldboardid, oldselfid)
|
||||
SELECT parentid = 0, ip, timestamp, name, tripcode, false, email, subject,
|
||||
message, message_raw, password, deleted_timestamp, deleted_timestamp > '2000-01-01', CASE WHEN parentid = 0 THEN id ELSE parentid, boardid from DBPREFIXposts_old;
|
||||
message, message_raw, password, deleted_timestamp, deleted_timestamp > '2000-01-01', id, boardid, id from DBPREFIXposts_old WHERE parentid = 0;
|
||||
|
||||
INSERT INTO DBPREFIXposts(is_top_post, ip, created_on, name, tripcode, is_role_signature, email, subject, message, message_raw, password, deleted_at, is_deleted, oldparentid, oldboardid, oldselfid)
|
||||
SELECT parentid = 0, ip, timestamp, name, tripcode, false, email, subject,
|
||||
message, message_raw, password, deleted_timestamp, deleted_timestamp > '2000-01-01', parentid, boardid, id from DBPREFIXposts_old WHERE parentid <> 0;
|
||||
|
||||
#IF NEVER
|
||||
UPDATE DBPREFIXposts as posts
|
||||
SET thread_id = thread.id
|
||||
FROM DBPREFIXthreads as threads
|
||||
WHERE threads.oldpostid = posts.oldparentid AND thread.board_id = posts.oldboardid;
|
||||
|
||||
/*
|
||||
UPDATE DBPREFIXposts as posts, DBPREFIXthreads as threads
|
||||
SET posts.thread_id = thread.id
|
||||
WHERE threads.oldpostid = posts.oldparentid AND thread.board_id = posts.oldboardid;
|
||||
|
||||
*/
|
||||
INSERT INTO DBPREFIXfiles(file_oder, original_filename, filename, checksum, file_size, is_spoilered, width, height, thumbnail_width, thumbnail_height, oldpostid, oldboardid)
|
||||
SELECT 1, filename_original, filename, file_checksum, filesize, false, image_w, image_h, thumb_w, thumb_h, id, boardid FROM DBPREFIXposts_old WHERE filename != '';
|
||||
|
||||
|
@ -92,3 +113,6 @@ UPDATE DBPREFIXfiles as files, DBPREFIXposts as posts
|
|||
SET files.post_id = posts.id
|
||||
WHERE files.oldpostid = posts.oldselfid AND files.oldboardid = posts.oldboardid;
|
||||
|
||||
--Redefine foreign keys and not nulls
|
||||
|
||||
#ENDIF NEVER
|
|
@ -69,26 +69,22 @@ ALTER TABLE DBPREFIXthreads ADD oldpostid int;
|
|||
ALTER TABLE DBPREFIXposts ADD oldselfid int;
|
||||
ALTER TABLE DBPREFIXposts ADD oldparentid int;
|
||||
ALTER TABLE DBPREFIXposts ADD oldboardid int;
|
||||
ALTER TABLE DBPREFIXposts DROP FOREIGN KEY thread_id;
|
||||
ALTER TABLE DBPREFIXposts DROP FOREIGN KEY posts_thread_id_fk;
|
||||
ALTER TABLE DBPREFIXfiles ADD oldpostid int;
|
||||
ALTER TABLE DBPREFIXfiles ADD oldboardid int;
|
||||
ALTER TABLE DBPREFIXfiles DROP FOREIGN KEY post_id;
|
||||
ALTER TABLE DBPREFIXfiles DROP FOREIGN KEY files_post_id_fk;
|
||||
-- Drops not null constraint
|
||||
ALTER TABLE DBPREFIXposts MODIFY thread_id BIGINT;
|
||||
ALTER TABLE DBPREFIXfiles MODIFY post_id BIGINT;
|
||||
|
||||
INSERT INTO DBPREFIXthreads(board_id, locked, stickied, anchored, last_bump, is_deleted, deleted_at, oldpostid)
|
||||
SELECT boardid, locked, stickied, autosage, bumped, deleted_timestamp > '2000-01-01', deleted_timestamp, id FROM DBPREFIXposts_old WHERE parentid = 0;
|
||||
|
||||
INSERT INTO DBPREFIXposts(is_top_post, ip, created_on, name, tripcode, is_role_signature, email, subject, message, message_raw, password, deleted_at, is_deleted, oldparentid, oldboardid)
|
||||
INSERT INTO DBPREFIXposts(is_top_post, ip, created_on, name, tripcode, is_role_signature, email, subject, message, message_raw, password, deleted_at, is_deleted, oldparentid, oldboardid, oldselfid)
|
||||
SELECT parentid = 0, ip, timestamp, name, tripcode, false, email, subject,
|
||||
message, message_raw, password, deleted_timestamp, deleted_timestamp > '2000-01-01', CASE WHEN parentid = 0 THEN id ELSE parentid, boardid from DBPREFIXposts_old;
|
||||
message, message_raw, password, deleted_timestamp, deleted_timestamp > '2000-01-01', id, boardid, id from DBPREFIXposts_old WHERE parentid = 0;
|
||||
|
||||
UPDATE DBPREFIXposts as posts, DBPREFIXthreads as threads
|
||||
SET posts.thread_id = thread.id
|
||||
WHERE threads.oldpostid = posts.oldparentid AND thread.board_id = posts.oldboardid;
|
||||
|
||||
INSERT INTO DBPREFIXfiles(file_oder, original_filename, filename, checksum, file_size, is_spoilered, width, height, thumbnail_width, thumbnail_height, oldpostid, oldboardid)
|
||||
SELECT 1, filename_original, filename, file_checksum, filesize, false, image_w, image_h, thumb_w, thumb_h, id, boardid FROM DBPREFIXposts_old WHERE filename != '';
|
||||
|
||||
UPDATE DBPREFIXfiles as files, DBPREFIXposts as posts
|
||||
SET files.post_id = posts.id
|
||||
WHERE files.oldpostid = posts.oldselfid AND files.oldboardid = posts.oldboardid;
|
||||
INSERT INTO DBPREFIXposts(is_top_post, ip, created_on, name, tripcode, is_role_signature, email, subject, message, message_raw, password, deleted_at, is_deleted, oldparentid, oldboardid, oldselfid)
|
||||
SELECT parentid = 0, ip, timestamp, name, tripcode, false, email, subject,
|
||||
message, message_raw, password, deleted_timestamp, deleted_timestamp > '2000-01-01', parentid, boardid, id from DBPREFIXposts_old WHERE parentid <> 0;
|
||||
|
||||
|
|
|
@ -69,26 +69,22 @@ ALTER TABLE DBPREFIXthreads ADD oldpostid int;
|
|||
ALTER TABLE DBPREFIXposts ADD oldselfid int;
|
||||
ALTER TABLE DBPREFIXposts ADD oldparentid int;
|
||||
ALTER TABLE DBPREFIXposts ADD oldboardid int;
|
||||
ALTER TABLE DBPREFIXposts DROP CONSTRAINT thread_id;
|
||||
ALTER TABLE DBPREFIXposts DROP CONSTRAINT posts_thread_id_fk;
|
||||
ALTER TABLE DBPREFIXfiles ADD oldpostid int;
|
||||
ALTER TABLE DBPREFIXfiles ADD oldboardid int;
|
||||
ALTER TABLE DBPREFIXfiles DROP CONSTRAINT post_id;
|
||||
ALTER TABLE DBPREFIXfiles DROP CONSTRAINT files_post_id_fk;
|
||||
-- Drops not null constraint
|
||||
ALTER TABLE DBPREFIXposts ALTER COLUMN thread_id DROP NOT NULL;
|
||||
ALTER TABLE DBPREFIXfiles ALTER COLUMN post_id DROP NOT NULL;
|
||||
|
||||
INSERT INTO DBPREFIXthreads(board_id, locked, stickied, anchored, last_bump, is_deleted, deleted_at, oldpostid)
|
||||
SELECT boardid, locked, stickied, autosage, bumped, deleted_timestamp > '2000-01-01', deleted_timestamp, id FROM DBPREFIXposts_old WHERE parentid = 0;
|
||||
|
||||
INSERT INTO DBPREFIXposts(is_top_post, ip, created_on, name, tripcode, is_role_signature, email, subject, message, message_raw, password, deleted_at, is_deleted, oldparentid, oldboardid)
|
||||
INSERT INTO DBPREFIXposts(is_top_post, ip, created_on, name, tripcode, is_role_signature, email, subject, message, message_raw, password, deleted_at, is_deleted, oldparentid, oldboardid, oldselfid)
|
||||
SELECT parentid = 0, ip, timestamp, name, tripcode, false, email, subject,
|
||||
message, message_raw, password, deleted_timestamp, deleted_timestamp > '2000-01-01', CASE WHEN parentid = 0 THEN id ELSE parentid, boardid from DBPREFIXposts_old;
|
||||
message, message_raw, password, deleted_timestamp, deleted_timestamp > '2000-01-01', id, boardid, id from DBPREFIXposts_old WHERE parentid = 0;
|
||||
|
||||
UPDATE DBPREFIXposts as posts, DBPREFIXthreads as threads
|
||||
SET posts.thread_id = thread.id
|
||||
WHERE threads.oldpostid = posts.oldparentid AND thread.board_id = posts.oldboardid;
|
||||
|
||||
INSERT INTO DBPREFIXfiles(file_oder, original_filename, filename, checksum, file_size, is_spoilered, width, height, thumbnail_width, thumbnail_height, oldpostid, oldboardid)
|
||||
SELECT 1, filename_original, filename, file_checksum, filesize, false, image_w, image_h, thumb_w, thumb_h, id, boardid FROM DBPREFIXposts_old WHERE filename != '';
|
||||
|
||||
UPDATE DBPREFIXfiles as files, DBPREFIXposts as posts
|
||||
SET files.post_id = posts.id
|
||||
WHERE files.oldpostid = posts.oldselfid AND files.oldboardid = posts.oldboardid;
|
||||
INSERT INTO DBPREFIXposts(is_top_post, ip, created_on, name, tripcode, is_role_signature, email, subject, message, message_raw, password, deleted_at, is_deleted, oldparentid, oldboardid, oldselfid)
|
||||
SELECT parentid = 0, ip, timestamp, name, tripcode, false, email, subject,
|
||||
message, message_raw, password, deleted_timestamp, deleted_timestamp > '2000-01-01', parentid, boardid, id from DBPREFIXposts_old WHERE parentid <> 0;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue