# Path: odpw/core/model.py
# class Portal(Base):
# class PortalSnapshot(Base):
# class Serializable(object):
# class PortalSnapshotDynamicity(Base,Serializable):
# class PortalSnapshotQuality(Base):
# class Dataset(Base):
# class DatasetData(Base):
# class DatasetQuality(Base):
# class MetaResource(Base):
# class ResourceInfo(Base):
# class ResourceCrawlLog(Base):
# class ResourceHistory(Base):
# class ResourceFreshness(Base):
# class FormatDist(Base):
#     def snapshot_count(self):
#     def snapshot_count(cls):
#     def first_snapshot(self):
#     def first_snapshot(cls):
#     def last_snapshot(self):
#     def last_snapshot(cls):
#     def datasetcount(self):
#     def datasetcount(cls):
#     def resourcecount(self):
#     def resourcecount(cls):
#     def __repr__(self):
#     def fetchtime(self):
#     def __repr__(self):
#     def to_dict(self):
#     def dyratio(self):
#     def adddelratio(self):
#     def addRatio(self):
#     def delRatio(self):
#     def updatedRatio(self):
#     def staticRatio(self):
#     def __repr__(self):
#     def __repr__(self):
#     def __repr__(self):
#     def __repr__(self):
#     def info(cls):
#     def __repr__(self):


from collections import defaultdict
from sqlalchemy import create_engine, inspect
from sqlalchemy import event
from sqlalchemy import exc
from sqlalchemy.engine import reflection
from sqlalchemy.orm import sessionmaker
from sqlalchemy.schema import (
    MetaData,
    Table,
    DropTable,
    ForeignKeyConstraint,
    DDL
)
from sqlalchemy.sql.ddl import DropConstraint
from odpw.core.model import Dataset, Base, tab_datasets, tab_resourcesinfo, ResourceInfo, tab_resourcescrawllog
import os
import structlog
import time
            for fk in inspector.get_foreign_keys(table_name):
                if not fk['name']:
                    continue
                fks.append(
                    ForeignKeyConstraint((), (), name=fk['name'])
                )
            t = Table(table_name, metadata, *fks)
            tbs.append(t)
            all_fks.extend(fks)

        for fkc in all_fks:
            conn.execute(DropConstraint(fkc, cascade=True))

        for table in tbs:
            if table.name != tab_datasets and table.name != tab_resourcesinfo:
                conn.execute(DropTable(table))

        trans.commit()

    def tableExists(self,Variable_tableName):
        return self.engine.has_table(self.engine, Variable_tableName)
    def viewExists(self,Variable_tableName):
        print 'check if table {} exists'.format(Variable_tableName)
        return self.engine.connect().execute()

    def init(self, Base):

        event.listen(Dataset.__table__, 'after_create', self.dataset_insert_function)
        event.listen(Dataset.__table__, 'after_create', self.dataset_insert_trigger)
        event.listen(ResourceInfo.__table__, 'after_create', self.resourcesinfo_insert_function)

# Path: odpw/core/model.py
# class Portal(Base):
# class PortalSnapshot(Base):
# class Serializable(object):
# class PortalSnapshotDynamicity(Base,Serializable):
# class PortalSnapshotQuality(Base):
# class Dataset(Base):
# class DatasetData(Base):
# class DatasetQuality(Base):
# class MetaResource(Base):
# class ResourceInfo(Base):
# class ResourceCrawlLog(Base):
# class ResourceHistory(Base):
# class ResourceFreshness(Base):
# class FormatDist(Base):
#     def snapshot_count(self):
#     def snapshot_count(cls):
#     def first_snapshot(self):
#     def first_snapshot(cls):
#     def last_snapshot(self):
#     def last_snapshot(cls):
#     def datasetcount(self):
#     def datasetcount(cls):
#     def resourcecount(self):
#     def resourcecount(cls):
#     def __repr__(self):
#     def fetchtime(self):
#     def __repr__(self):
#     def to_dict(self):
#     def dyratio(self):
#     def adddelratio(self):
#     def addRatio(self):
#     def delRatio(self):
#     def updatedRatio(self):
#     def staticRatio(self):
#     def __repr__(self):
#     def __repr__(self):
#     def __repr__(self):
#     def __repr__(self):
#     def info(cls):
#     def __repr__(self):


# Path: odpw/core/db.py
from collections import defaultdict
from sqlalchemy import create_engine, inspect
from sqlalchemy import event
from sqlalchemy import exc
from sqlalchemy.engine import reflection
from sqlalchemy.orm import sessionmaker
from sqlalchemy.schema import (
    MetaData,
    Table,
    DropTable,
    ForeignKeyConstraint,
    DDL
)
from sqlalchemy.sql.ddl import DropConstraint
from odpw.core.model import Dataset, Base, tab_datasets, tab_resourcesinfo, ResourceInfo, tab_resourcescrawllog
import os
import structlog
import time

            for fk in inspector.get_foreign_keys(table_name):
                if not fk['name']:
                    continue
                fks.append(
                    ForeignKeyConstraint((), (), name=fk['name'])
                )
            t = Table(table_name, metadata, *fks)
            tbs.append(t)
            all_fks.extend(fks)

        for fkc in all_fks:
            conn.execute(DropConstraint(fkc, cascade=True))

        for table in tbs:
            if table.name != tab_datasets and table.name != tab_resourcesinfo:
                conn.execute(DropTable(table))

        trans.commit()

    def tableExists(self,Variable_tableName):
        return self.engine.has_table(self.engine, Variable_tableName)
    def viewExists(self,Variable_tableName):
        print 'check if table {} exists'.format(Variable_tableName)
        return self.engine.connect().execute()

    def init(self, Base):

        event.listen(Dataset.__table__, 'after_create', self.dataset_insert_function)
        event.listen(Dataset.__table__, 'after_create', self.dataset_insert_trigger)
        event.listen(ResourceInfo.__table__, 'after_create', self.resourcesinfo_insert_function)

        event.listen(ResourceInfo.__table__, 'after_create', self.resourcesinfo_insert_trigger)