#NEWLINE# def update_database( dbfile ) : #NEWLINE# #INDENT# conn = sqlite3 . connect ( dbfile ) #NEWLINE# conn . row_factory = sqlite3 . Row #NEWLINE# with conn : #NEWLINE# #INDENT# c = conn . cursor ( ) #NEWLINE# c . execute ( 'ALTER TABLE volunteers RENAME TO volunteers_old' ) #NEWLINE# c . execute ( 'CREATE TABLE "volunteers" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" VARCHAR(255), "orientation" TIMESTAMP, "status" VARCHAR(255), "created_at" TIMESTAMP, "updated_at" TIMESTAMP)' ) #NEWLINE# c . execute ( 'SELECT id, name, orientation, status, created_at, updated_at FROM volunteers_old' ) #NEWLINE# volunteers = c . fetchall ( ) #NEWLINE# for row in volunteers : #NEWLINE# #INDENT# c . execute ( 'INSERT INTO volunteers (id, name, orientation, status, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?)' , ( volunteers [ 'id' ] , row [ 'name' ] , row [ 'orientation' ] , row [ 'status' ] , row [ 'created_at' ] , row [ 'updated_at' ] ) ) #NEWLINE# #UNINDENT# c . execute ( 'DROP TABLE volunteers_old' ) #NEWLINE# c . execute ( 'CREATE TABLE "activities" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" VARCHAR(255), "status" VARCHAR(255), "created_at" TIMESTAMP, "updated_at" TIMESTAMP)' ) #NEWLINE# c . execute ( 'SELECT id, name, created_at, updated_at FROM categories' ) #NEWLINE# categories = c . fetchall ( ) #NEWLINE# for row in categories : #NEWLINE# #INDENT# c . execute ( 'INSERT INTO activities (id, name, status, created_at, updated_at) VALUES (?, ?, ?, ?, ?)' , ( row [ 'id' ] , row [ 'name' ] , 'active' , row [ 'created_at' ] , row [ 'updated_at' ] ) ) #NEWLINE# #UNINDENT# c . execute ( 'DROP TABLE categories' ) #NEWLINE# c . execute ( 'ALTER TABLE hours RENAME TO hours_old' ) #NEWLINE# c . execute ( 'CREATE TABLE "hours" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "volunteer_id" INTEGER, "start" TIMESTAMP, "end" TIMESTAMP, "activity_id" INTEGER, "created_at" TIMESTAMP, "updated_at" TIMESTAMP)' ) #NEWLINE# c . execute ( 'SELECT id, volunteer_id, start, end, category_id, created_at, updated_at FROM hours_old' ) #NEWLINE# hours = c . fetchall ( ) #NEWLINE# for row in hours : #NEWLINE# #INDENT# c . execute ( 'INSERT INTO hours (id, volunteer_id, start, end, activity_id, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?)' , ( row [ 'id' ] , row [ 'volunteer_id' ] , row [ 'start' ] , row [ 'end' ] , row [ 'category_id' ] , row [ 'created_at' ] , row [ 'updated_at' ] ) ) #NEWLINE# #UNINDENT# c . execute ( 'DROP TABLE hours_old' ) #NEWLINE# c . execute ( 'VACUUM' )