I forgot what I chanagerd
This commit is contained in:
1 parent
24081e1576
commit
c4f5018833
20 files changed
+678
-77
No files matched your search
@@ -0,0 +1,45 @@
|
||||
import sqlite3
|
||||
DB_PATH = "database.db"
|
||||
|
||||
def migrate_to_many(db_path):
|
||||
con = sqlite3.connect(db_path)
|
||||
cur = con.cursor()
|
||||
cur.execute("PRAGMA foreign_keys=OFF;")
|
||||
try:
|
||||
con.execute("BEGIN;")
|
||||
cur.execute("ALTER TABLE youtube_info RENAME TO youtube_info_old;")
|
||||
|
||||
cur.execute("""
|
||||
CREATE TABLE youtube_info (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
twitch_video_id VARCHAR NOT NULL,
|
||||
yt_id VARCHAR,
|
||||
yt_date VARCHAR,
|
||||
yt_short_id VARCHAR,
|
||||
yt_short_date VARCHAR,
|
||||
yt_chat_SS_id VARCHAR,
|
||||
yt_chat_SS_date VARCHAR,
|
||||
yt_chat_over_id VARCHAR,
|
||||
yt_chat_over_date VARCHAR,
|
||||
FOREIGN KEY(twitch_video_id) REFERENCES twitch_videos(id) ON DELETE CASCADE
|
||||
);
|
||||
""")
|
||||
cur.execute("CREATE INDEX ix_youtube_info_twitch_video_id ON youtube_info (twitch_video_id);")
|
||||
|
||||
cur.execute("""
|
||||
INSERT INTO youtube_info (twitch_video_id, yt_id, yt_date, yt_short_id, yt_short_date, yt_chat_SS_id, yt_chat_SS_date, yt_chat_over_id, yt_chat_over_date)
|
||||
SELECT id, yt_id, yt_date, yt_short_id, yt_short_date, yt_chat_SS_id, yt_chat_SS_date, yt_chat_over_id, yt_chat_over_date
|
||||
FROM youtube_info_old;
|
||||
""")
|
||||
|
||||
cur.execute("DROP TABLE youtube_info_old;")
|
||||
con.commit()
|
||||
print("Done - now 1-to-Many")
|
||||
except Exception as e:
|
||||
con.rollback()
|
||||
raise e
|
||||
finally:
|
||||
cur.execute("PRAGMA foreign_keys=ON;")
|
||||
con.close()
|
||||
|
||||
migrate_to_many(DB_PATH)
|
||||
Reference in new issue
Block a user