Last active
December 17, 2015 10:39
-
-
Save lepture/5596439 to your computer and use it in GitHub Desktop.
upgrade python china
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@manager.command | |
def sync(): | |
from june.models import db, Account, Node, Topic, NodeStatus | |
users = Account.query.all() | |
nodes = Node.query.all() | |
for user in users: | |
print('save %i %s' % (user.id, user)) | |
if not user.username: | |
username = user.email.split('@')[0] | |
if len(username) < 3: | |
username = raw_input('username of %s: ' % user.email) | |
user.username = username | |
if not user.screen_name: | |
user.screen_name = user.username | |
user.username = user.username.lower() | |
if not user.active: | |
topic = Topic.query.filter_by( | |
account_id=user.id | |
).order_by(Topic.id.desc()).first() | |
if topic: | |
user.active = topic.created | |
db.session.add(user) | |
for node in nodes: | |
topic_count = Topic.query.filter_by( | |
account_id=user.id, node_id=node.id).count() | |
ns = NodeStatus.query.filter_by( | |
account_id=user.id, node_id=node.id).first() | |
if not ns: | |
ns = NodeStatus(account_id=user.id, node_id=node.id) | |
ns.topic_count = topic_count | |
db.session.add(ns) | |
db.session.commit() | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE node_status ( | |
node_id INTEGER NOT NULL AUTO_INCREMENT, | |
account_id INTEGER NOT NULL, | |
topic_count INTEGER, | |
reputation INTEGER, | |
updated DATETIME, | |
PRIMARY KEY (node_id, account_id) | |
); | |
DROP TABLE follow_node; | |
DROP TABLE social; | |
DROP TABLE storage; | |
DROP TABLE vote; | |
DROP TABLE notification; | |
DROP TABLE feedback; | |
DROP TABLE topic_log; | |
DROP TABLE document; | |
RENAME TABLE member TO account; | |
ALTER TABLE account ADD COLUMN active DATETIME; | |
ALTER TABLE account ADD INDEX ix_account_active (active); | |
ALTER TABLE account ADD COLUMN screen_name VARCHAR(80); | |
ALTER TABLE account DROP COLUMN reputation; | |
ALTER TABLE account DROP COLUMN edit_username_count; | |
ALTER TABLE account DROP COLUMN avatar; | |
ALTER TABLE account CHANGE role old_role INTEGER; | |
ALTER TABLE account ADD COLUMN role VARCHAR(10); | |
UPDATE account set role='user' WHERE old_role>1; | |
UPDATE account set role='new' WHERE old_role=1; | |
ALTER TABLE account DROP COLUMN old_role; | |
DROP INDEX ix_member_username ON account; | |
ALTER TABLE account CHANGE username username VARCHAR(100) NOT NULL; | |
/* TODO */ | |
DROP INDEX ix_member_email ON account; | |
ALTER TABLE account CHANGE email email VARCHAR(200) NOT NULL; | |
ALTER TABLE account ADD UNIQUE KEY ix_account_email (email); | |
ALTER TABLE account CHANGE description description VARCHAR(400) NULL; | |
/* node */ | |
ALTER TABLE node CHANGE slug urlname VARCHAR(40); | |
ALTER TABLE node ADD COLUMN role VARCHAR(10); | |
ALTER TABLE node DROP COLUMN limit_reputation; | |
ALTER TABLE node DROP COLUMN header; | |
ALTER TABLE node DROP COLUMN footer; | |
ALTER TABLE node DROP COLUMN bgcolor; | |
ALTER TABLE node DROP COLUMN avatar; | |
ALTER TABLE node DROP COLUMN sidebar; | |
ALTER TABLE node DROP COLUMN fgcolor; | |
UPDATE node SET role='staff' WHERE limit_role > 3; | |
UPDATE node set role='user' WHERE limit_role < 3; | |
ALTER TABLE node DROP COLUMN limit_role; | |
/* reply */ | |
ALTER TABLE reply ADD COLUMN flags INTEGER; | |
DROP INDEX ix_reply_user_id ON reply; | |
ALTER TABLE reply CHANGE user_id account_id INTEGER NOT NULL; | |
CREATE INDEX ix_reply_account_id ON reply (account_id); | |
ALTER TABLE reply DROP COLUMN accepted; | |
DROP INDEX ix_reply_topic_id ON reply; | |
ALTER TABLE reply CHANGE topic_id topic_id INTEGER NOT NULL; | |
CREATE INDEX ix_reply_topic_id ON reply (topic_id); | |
/* topic */ | |
DROP INDEX ix_topic_user_id ON topic; | |
ALTER TABLE topic CHANGE user_id account_id INTEGER NOT NULL; | |
CREATE INDEX ix_topic_account_id ON topic (account_id); | |
ALTER TABLE topic DROP COLUMN impact; | |
ALTER TABLE topic DROP COLUMN status; | |
ALTER TABLE topic DROP COLUMN last_reply_by; | |
ALTER TABLE topic DROP COLUMN down_count; | |
ALTER TABLE topic DROP COLUMN last_reply_time; | |
ALTER TABLE topic DROP COLUMN up_count; | |
ALTER TABLE topic CHANGE title title VARCHAR(200) NOT NULL; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
处理完所有用户才
session.commit()
,这个 commit 的量是不是大了些?