-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb_migrate.py
More file actions
45 lines (26 loc) · 1.06 KB
/
db_migrate.py
File metadata and controls
45 lines (26 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# project/migrate.py
from views import db
from _config import DATABASE_PATH
import sqlite3
from datetime import datetime
#with sqlite3.connect(DATABASE_PATH) as connection:
# c = connection.cursor()
# c.execute("""ALTER TABLE tasks RENAME to old_tasks""")
# db.create_all()
# c.execute("""SELECT name, due_date, priority,
# status FROM old_tasks ORDER BY task_id ASC""")
# data = [(row[0], row[1], row[2], row[3],
# datetime.now(), 1) for row in c.fetchall()]
# c.executemany("""INSERT INTO tasks (name, due_date, priority, status,
# posted_date, user_id) VALUES (?, ?, ?, ?, ?, ?)""", data)
# c.execute("DROP TABLE old_tasks")
with sqlite3.connect(DATABASE_PATH) as connection:
c = connection.cursor()
c.execute("""ALTER TABLE users RENAME to old_users""")
db.create_all()
c.execute("""SELECT name, email, password
FROM old_users ORDER BY id ASC""")
data = [(row[0], row[1], row[2], 'user') for row in c.fetchall()]
c.executemany("""INSERT INTO users (name, email, password, role)
VALUES (?, ?, ?, ?)""", data)
c.execute("DROP TABLE old_users")