This repository has been archived on 2023-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
python-blog/migration.py

37 lines
1.1 KiB
Python
Raw Normal View History

2020-08-16 20:24:08 +02:00
import sqlite3
def main():
2020-08-17 08:52:30 +02:00
writefreely = sqlite3.connect("db/writefreely.db")
db = sqlite3.connect("db/db.sqlite3")
2020-08-16 20:24:08 +02:00
writefreely_c = writefreely.cursor()
db_c = db.cursor()
writefreely_c.execute(
2020-08-17 09:57:24 +02:00
"SELECT slug, created, updated, view_count, title, content, pinned_position FROM posts;"
2020-08-16 20:24:08 +02:00
)
for line in writefreely_c.fetchall():
2020-08-17 09:57:24 +02:00
ret = db_c.execute(
2020-08-16 20:24:08 +02:00
"INSERT INTO articles_article(title, content, status, published_at, created_at, updated_at, author_id, views_count, slug) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);",
(
line[4],
line[5],
"published",
line[1],
line[1],
line[2],
1,
line[3],
line[0],
),
)
2020-08-17 09:57:24 +02:00
if line[6] is not None:
db_c.execute(
2020-08-17 10:13:27 +02:00
"INSERT INTO articles_page(article_ptr_id, position) VALUES (?, ?);",
(ret.lastrowid, line[6]),
2020-08-17 09:57:24 +02:00
)
2020-08-16 20:24:08 +02:00
db.commit()
if __name__ == "__main__":
main()