Show More
@@ -32,27 +32,27 b' def upgrade(migrate_engine):' | |||||
32 | # create username column |
|
32 | # create username column | |
33 | username.create(table=tbl) |
|
33 | username.create(table=tbl) | |
34 |
|
34 | |||
35 | #alter user_id to not null |
|
35 | _Session = Session() | |
|
36 | ## after adding that column fix all usernames | |||
|
37 | users_log = _Session.query(UserLog)\ | |||
|
38 | .options(joinedload(UserLog.user))\ | |||
|
39 | .options(joinedload(UserLog.repository)).all() | |||
|
40 | ||||
|
41 | for entry in users_log: | |||
|
42 | entry.username = entry.user.username | |||
|
43 | _Session.add(entry) | |||
|
44 | _Session.commit() | |||
|
45 | ||||
|
46 | #alter username to not null | |||
36 | from rhodecode.lib.dbmigrate.schema.db_1_5_0 import UserLog |
|
47 | from rhodecode.lib.dbmigrate.schema.db_1_5_0 import UserLog | |
37 | tbl_name = UserLog.__tablename__ |
|
48 | tbl_name = UserLog.__tablename__ | |
38 | tbl = Table(tbl_name, |
|
49 | tbl = Table(tbl_name, | |
39 | MetaData(bind=migrate_engine), autoload=True, |
|
50 | MetaData(bind=migrate_engine), autoload=True, | |
40 | autoload_with=migrate_engine) |
|
51 | autoload_with=migrate_engine) | |
41 |
col = tbl.columns.user |
|
52 | col = tbl.columns.username | |
42 |
|
53 | |||
43 | # remove nullability from revision field |
|
54 | # remove nullability from revision field | |
44 |
col.alter(nullable= |
|
55 | col.alter(nullable=False) | |
45 |
|
||||
46 |
|
||||
47 |
|
||||
48 | ## after adding that column fix all usernames |
|
|||
49 | users_log = UserLog.query()\ |
|
|||
50 | .options(joinedload(UserLog.user))\ |
|
|||
51 | .options(joinedload(UserLog.repository)).all() |
|
|||
52 | for entry in users_log: |
|
|||
53 | entry.username = entry.user.username |
|
|||
54 | Session().add(entry) |
|
|||
55 | Session().commit() |
|
|||
56 |
|
56 | |||
57 |
|
57 | |||
58 | def downgrade(migrate_engine): |
|
58 | def downgrade(migrate_engine): |
General Comments 0
You need to be logged in to leave comments.
Login now