예제 #1
0
def update_005():
    import web
    from infogami.infobase._dbstore.store import Store
    
    db = web.database(dbn="postgres", db="openlibrary", user=os.getenv("USER"), pw="")    
    store = Store(db)
    
    for row in db.query("SELECT thing.key, thing.created, account.* FROM thing, account WHERE thing.id=account.thing_id"):
        username = row.key.split("/")[-1]
        account_key = "account/" + username
        
        if store.get(account_key):
            continue
        else:
            account = {
                "_key": account_key,
                "type": "account",
                "email": row.email,
                "enc_password": row.password,
                
                "username": username,
                "lusername": username.lower(),
                
                "bot": row.bot,
                "status": row.verified and "verified" or "pending",
                "created_on": row.created.isoformat(),
            }
            email_doc = {
                "_key": "account-email/" + row.email,
                "type": "account-email",
                "username": username
            }
            store.put_many([account, email_doc])
def migrate_account_table(db):
    def get_status(row):
        if row.get("verified"):
            return "active"
        else:
            return "pending"
            
    with db.transaction():
        store = Store(db)
    
        db.query("DECLARE longquery NO SCROLL CURSOR FOR SELECT thing.key, thing.created, account.* FROM thing, account WHERE thing.id=account.thing_id")
        while True:
            rows = db.query("FETCH FORWARD 100 FROM longquery").list()
            if not rows:
                break
                
            docs = []
            for row in rows:
                # Handle bad rows in the thing table.
                if not row.key.startswith("/people/"):
                    continue
                    
                username = row.key.split("/")[-1]
                doc = {
                    "_key": "account/" + username,
                    "type": "account",
            
                    "status": get_status(row),
                    "created_on": row.created.isoformat(),
            
                    "username": username,
                    "lusername": username.lower(),
            
                    "email": row.email,
                    "enc_password": row.password,
                    "bot": row.get("bot", False),
                }
                email_doc = {
                    "_key": "account-email/" + row.email,
                    "type": "account-email",
                    "username": username
                }
                docs.append(doc)
                docs.append(email_doc)
            store.put_many(docs)
예제 #3
0
def migrate_account_table(db):
    def get_status(row):
        if row.get("verified"):
            return "active"
        else:
            return "pending"

    with db.transaction():
        store = Store(db)

        db.query(
            "DECLARE longquery NO SCROLL CURSOR FOR SELECT thing.key, thing.created, account.* FROM thing, account WHERE thing.id=account.thing_id"
        )
        while True:
            rows = db.query("FETCH FORWARD 100 FROM longquery").list()
            if not rows:
                break

            docs = []
            for row in rows:
                # Handle bad rows in the thing table.
                if not row.key.startswith("/people/"):
                    continue

                username = row.key.split("/")[-1]
                doc = {
                    "_key": "account/" + username,
                    "type": "account",
                    "status": get_status(row),
                    "created_on": row.created.isoformat(),
                    "username": username,
                    "lusername": username.lower(),
                    "email": row.email,
                    "enc_password": row.password,
                    "bot": row.get("bot", False),
                }
                email_doc = {
                    "_key": "account-email/" + row.email,
                    "type": "account-email",
                    "username": username
                }
                docs.append(doc)
                docs.append(email_doc)
            store.put_many(docs)
예제 #4
0
def update_005():
    import web
    from infogami.infobase._dbstore.store import Store

    db = web.database(dbn="postgres",
                      db="openlibrary",
                      user=os.getenv("USER"),
                      pw="")
    store = Store(db)

    for row in db.query(
            "SELECT thing.key, thing.created, account.* FROM thing, account WHERE thing.id=account.thing_id"
    ):
        username = row.key.split("/")[-1]
        account_key = "account/" + username

        if store.get(account_key):
            continue
        else:
            account = {
                "_key": account_key,
                "type": "account",
                "email": row.email,
                "enc_password": row.password,
                "username": username,
                "lusername": username.lower(),
                "bot": row.bot,
                "status": row.verified and "verified" or "pending",
                "created_on": row.created.isoformat(),
            }
            email_doc = {
                "_key": "account-email/" + row.email,
                "type": "account-email",
                "username": username
            }
            store.put_many([account, email_doc])