# Path: odpw/core/model.py
# class ResourceInfo(Base):
#     __tablename__ = tab_resourcesinfo
# 
#     uri= Column(String, primary_key=True)
#     snapshot= Column(SmallInteger, primary_key=True)
#     timestamp= Column(TIMESTAMP)
#     status=Column(SmallInteger)
#     exc=Column(String)
#     header=Column(JSONB)
#     mime=Column(String)
#     size=Column(BigInteger)


import structlog
from odpw.core.model import ResourceInfo
from odpw.utils.timer import Timer
    from odpw.db.models import Resource


log =structlog.get_logger()




def resourceMigrate(snapshot, db, dbm):

    iter=Resource.iter(dbm.getResources(snapshot=snapshot))

    batch=[]
    for R in iter:
        uri=R.url
        uri=uri.replace("http:// \thttp:","http:")
        uri=uri.replace("http:// http://","http://")

        r={
            'snapshot':R.snapshot
            ,'uri':uri
            ,'timestamp':R.timestamp
            ,'status':R.status
            ,'exc':R.exception
            ,'header':R.header
            ,'mime':R.mime
            ,'size':R.size
        }

# Path: odpw/core/model.py
# class ResourceInfo(Base):
#     __tablename__ = tab_resourcesinfo
# 
#     uri= Column(String, primary_key=True)
#     snapshot= Column(SmallInteger, primary_key=True)
#     timestamp= Column(TIMESTAMP)
#     status=Column(SmallInteger)
#     exc=Column(String)
#     header=Column(JSONB)
#     mime=Column(String)
#     size=Column(BigInteger)


# Path: odpw/services/resourceinfo_insert.py
import structlog
from odpw.core.model import ResourceInfo
from odpw.utils.timer import Timer
    from odpw.db.models import Resource



log =structlog.get_logger()




def resourceMigrate(snapshot, db, dbm):

    iter=Resource.iter(dbm.getResources(snapshot=snapshot))

    batch=[]
    for R in iter:
        uri=R.url
        uri=uri.replace("http:// \thttp:","http:")
        uri=uri.replace("http:// http://","http://")

        r={
            'snapshot':R.snapshot
            ,'uri':uri
            ,'timestamp':R.timestamp
            ,'status':R.status
            ,'exc':R.exception
            ,'header':R.header
            ,'mime':R.mime
            ,'size':R.size
        }

        RI=ResourceInfo(**r)