Implements importer for old DB.
This commit is contained in:
parent
348a5df509
commit
3d860e9654
2 changed files with 86 additions and 7 deletions
66
src/importer.nim
Normal file
66
src/importer.nim
Normal file
|
|
@ -0,0 +1,66 @@
|
||||||
|
import db_sqlite, strutils
|
||||||
|
|
||||||
|
let origFile = "nimforum.db-21-05-18"
|
||||||
|
let targetFile = "nimforum-blank.db"
|
||||||
|
|
||||||
|
let orig = open(connection=origFile, user="", password="",
|
||||||
|
database="nimforum")
|
||||||
|
let target = open(connection=targetFile, user="", password="",
|
||||||
|
database="nimforum")
|
||||||
|
|
||||||
|
block:
|
||||||
|
let fields = "id, name, views, modified"
|
||||||
|
for thread in getAllRows(orig, sql("select $1 from thread;" % fields)):
|
||||||
|
target.exec(
|
||||||
|
sql("""
|
||||||
|
insert into thread($1)
|
||||||
|
values (?, ?, ?, ?)
|
||||||
|
""" % fields),
|
||||||
|
thread
|
||||||
|
)
|
||||||
|
|
||||||
|
block:
|
||||||
|
let fields = "id, name, password, email, creation, salt, status, lastOnline"
|
||||||
|
for person in getAllRows(orig, sql("select $1 from person;" % fields)):
|
||||||
|
target.exec(
|
||||||
|
sql("""
|
||||||
|
insert into person($1)
|
||||||
|
values (?, ?, ?, ?, ?, ?, ?, ?)
|
||||||
|
""" % fields),
|
||||||
|
person
|
||||||
|
)
|
||||||
|
|
||||||
|
block:
|
||||||
|
let fields = "id, author, ip, content, thread, creation"
|
||||||
|
for post in getAllRows(orig, sql("select $1 from post;" % fields)):
|
||||||
|
target.exec(
|
||||||
|
sql("""
|
||||||
|
insert into post($1)
|
||||||
|
values (?, ?, ?, ?, ?, ?)
|
||||||
|
""" % fields),
|
||||||
|
post
|
||||||
|
)
|
||||||
|
|
||||||
|
block:
|
||||||
|
let fields = "id, name"
|
||||||
|
for t in getAllRows(orig, sql("select $1 from thread_fts;" % fields)):
|
||||||
|
target.exec(
|
||||||
|
sql("""
|
||||||
|
insert into thread_fts($1)
|
||||||
|
values (?, ?)
|
||||||
|
""" % fields),
|
||||||
|
t
|
||||||
|
)
|
||||||
|
|
||||||
|
block:
|
||||||
|
let fields = "id, content"
|
||||||
|
for p in getAllRows(orig, sql("select $1 from post_fts;" % fields)):
|
||||||
|
target.exec(
|
||||||
|
sql("""
|
||||||
|
insert into post_fts($1)
|
||||||
|
values (?, ?)
|
||||||
|
""" % fields),
|
||||||
|
p
|
||||||
|
)
|
||||||
|
|
||||||
|
echo("Imported!")
|
||||||
|
|
@ -97,6 +97,7 @@ proc initialiseDb(admin: tuple[username, password, email: string],
|
||||||
db.exec sql"create index PersonStatusIdx on person(status);"
|
db.exec sql"create index PersonStatusIdx on person(status);"
|
||||||
|
|
||||||
# Create default user.
|
# Create default user.
|
||||||
|
if admin.username.len != 0:
|
||||||
let salt = makeSalt()
|
let salt = makeSalt()
|
||||||
let password = makePassword(admin.password, salt)
|
let password = makePassword(admin.password, salt)
|
||||||
db.exec(sql"""
|
db.exec(sql"""
|
||||||
|
|
@ -228,6 +229,11 @@ proc initialiseConfig(
|
||||||
backup(path, some(pretty(j)))
|
backup(path, some(pretty(j)))
|
||||||
writeFile(path, pretty(j))
|
writeFile(path, pretty(j))
|
||||||
|
|
||||||
|
proc question(q: string): string =
|
||||||
|
while result.len == 0:
|
||||||
|
stdout.write(q)
|
||||||
|
result = stdin.readLine()
|
||||||
|
|
||||||
when isMainModule:
|
when isMainModule:
|
||||||
if paramCount() > 0:
|
if paramCount() > 0:
|
||||||
case paramStr(1)
|
case paramStr(1)
|
||||||
|
|
@ -265,5 +271,12 @@ when isMainModule:
|
||||||
admin=("admin", "admin", "admin@localhost.local"),
|
admin=("admin", "admin", "admin@localhost.local"),
|
||||||
dbPath
|
dbPath
|
||||||
)
|
)
|
||||||
|
of "--blank":
|
||||||
|
let dbPath = "nimforum-blank.db"
|
||||||
|
echo("Initialising blank DB...")
|
||||||
|
initialiseDb(
|
||||||
|
admin=("", "", ""),
|
||||||
|
dbPath
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
quit("--dev|--test")
|
quit("--dev|--test|--prod")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue