mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
Merge #5857
5857: Update move_sqlite.py to use sqlite3mysql r=Zwelf a=def- https://github.com/techouse/sqlite3-to-mysql/ Better method than text file with manual seds <!-- What is the motivation for the changes of this pull request? --> <!-- Note that builds and other checks will be run for your change. Don't feel intimidated by failures in some of the checks. If you can't resolve them yourself, experienced devs can also resolve them before merging your pull request. --> ## Checklist - [ ] Tested the change ingame - [ ] Provided screenshots if it is a visual change - [ ] Tested in combination with possibly related configuration options - [ ] Written a unit test (especially base/) or added coverage to integration test - [ ] Considered possible null pointers and out of bounds array indexing - [ ] Changed no physics that affect existing maps - [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional) Co-authored-by: Dennis Felsing <dennis@felsin9.de>
This commit is contained in:
commit
3b7e963760
|
@ -34,6 +34,7 @@ def transfer(file_from, file_to):
|
|||
cursor_to = conn_to.cursor()
|
||||
|
||||
conn_from = sqlite3.connect(file_from, isolation_level='EXCLUSIVE')
|
||||
conn_from.text_factory = lambda b: b.decode(errors = 'ignore').rstrip()
|
||||
for line in conn_from.iterdump():
|
||||
cursor_to.execute(line)
|
||||
print(line.encode('utf-8'))
|
||||
|
@ -78,17 +79,11 @@ def main():
|
|||
if num == 0:
|
||||
return
|
||||
|
||||
print(f'{num} new entries in backup database found ({num_ranks} ranks, {num_teamranks} teamranks, {num_saves} saves')
|
||||
print('Moving entries from {os.path.abspath(args.f)} to {os.path.abspath(args.to)}')
|
||||
sql_file = 'ddnet-server-' + strftime('%Y-%m-%d') + '.sql'
|
||||
print("You can use the following commands to import the entries to MySQL (use sed 's/record_/prefix_/' for other database prefixes):")
|
||||
print()
|
||||
print((f" echo '.dump --preserve-rowids' | sqlite3 {os.path.abspath(args.to)} | " + # including rowids, this forces sqlite to name all columns in each INSERT statement
|
||||
"grep -E '^INSERT INTO record_(race|teamrace|saves)' | " + # filter out inserts
|
||||
"sed -e 's/INSERT INTO/INSERT IGNORE INTO/' | " + # ignore duplicate rows
|
||||
f"sed -e 's/rowid,//' -e 's/VALUES([0-9]*,/VALUES(/' > {sql_file}")) # filter out rowids again
|
||||
print(f" mysql -u teeworlds -p'PW2' teeworlds < {sql_file}")
|
||||
print(f'{num} new entries in backup database found ({num_ranks} ranks, {num_teamranks} teamranks, {num_saves} saves)')
|
||||
print(f'Moving entries from {os.path.abspath(args.f)} to {os.path.abspath(args.to)}')
|
||||
print("You can use the following commands to import the entries to MySQL (using https://github.com/techouse/sqlite3-to-mysql/):")
|
||||
print()
|
||||
print(f"sqlite3mysql --sqlite-file {os.path.abspath(args.to)} --ignore-duplicate-keys --mysql-insert-method IGNORE --sqlite-tables record_race record_teamrace record_saves --mysql-password 'PW2' --mysql-host 'host' --mysql-database teeworlds --mysql-user teeworlds")
|
||||
print(f"When the ranks are transfered successfully to mysql, {os.path.abspath(args.to)} can be removed")
|
||||
print()
|
||||
print("Log of the transfer:")
|
||||
|
|
Loading…
Reference in a new issue