# -*- coding: utf-8 -*-
import datetime
from sqlalchemy import *
from config import MIGRATE_DATABSE_URI
from application import db
from models.user import User

class Users:
    def run(self):
        self.migrateUser()

    def migrateUser(self):
        db.engine.execute("truncate table user")
        engine = create_engine(MIGRATE_DATABSE_URI, encoding='utf-8',echo=True)
        connection = engine.connect()
        userslist = connection.execute("select *  from `oausers`")
        if userslist:
            tmpstamps=datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
            for userinfo in userslist:
                usertarget=User('',userinfo['user_id'],userinfo['user_name'],userinfo['domain_account'],userinfo['user_code']
                            ,userinfo['office_mail'],userinfo['cellphone'],tmpstamps,tmpstamps)
                db.session.add(usertarget)
                db.session.commit()

