Exemplo n.º 1
0
def wipe_database():
    logger.debug("Wiping all data from the DB.")

    # Sanity check to make sure we're not killing our prod db
    if not IS_TESTING_REAL_DATABASE and not isinstance(db.obj, SqliteDatabase):
        raise RuntimeError("Attempted to wipe production database!")

    db.drop_tables(all_models)
Exemplo n.º 2
0
def process(resources):
    response = []
    changed = True
    expected_tables = [
        "accesstoken",
        "accesstokenkind",
        "alembic_version",
        "apprblob",
        "apprblobplacement",
        "apprblobplacementlocation",
        "apprmanifest",
        "apprmanifestblob",
        "apprmanifestlist",
        "apprmanifestlistmanifest",
        "apprtag",
        "apprtagkind",
        "appspecificauthtoken",
        "blobupload",
        "buildtriggerservice",
        "deletednamespace",
        "derivedstorageforimage",
        "disablereason",
        "emailconfirmation",
        "externalnotificationevent",
        "externalnotificationmethod",
        "federatedlogin",
        "image",
        "imagestorage",
        "imagestoragelocation",
        "imagestorageplacement",
        "imagestoragesignature",
        "imagestoragesignaturekind",
        "imagestoragetransformation",
        "label",
        "labelsourcetype",
        "logentry",
        "logentry2",
        "logentry3",
        "logentrykind",
        "loginservice",
        "manifest",
        "manifestblob",
        "manifestchild",
        "manifestlabel",
        "manifestlegacyimage",
        "mediatype",
        "messages",
        "namespacegeorestriction",
        "notification",
        "notificationkind",
        "oauthaccesstoken",
        "oauthapplication",
        "oauthauthorizationcode",
        "permissionprototype",
        "quayregion",
        "quayrelease",
        "quayservice",
        "queueitem",
        "repomirrorconfig",
        "repomirrorrule",
        "robotaccountmetadata",
        "repository",
        "repositoryactioncount",
        "repositoryauthorizedemail",
        "repositorybuild",
        "repositorybuildtrigger",
        "repositorykind",
        "repositorynotification",
        "repositorypermission",
        "repositorysearchscore",
        "repositorytag",
        "role",
        "servicekey",
        "servicekeyapproval",
        "star",
        "tag",
        "tagkind",
        "tagmanifest",
        "tagmanifestlabel",
        "tagmanifestlabelmap",
        "tagmanifesttomanifest",
        "tagtorepositorytag",
        "team",
        "teammember",
        "teammemberinvite",
        "teamrole",
        "teamsync",
        "torrentinfo",
        "user",
        "userprompt",
        "userpromptkind",
        "userregion",
        "visibility",
    ]

    for resource in resources:
        p_state = resource["state"]

        if p_state == "reset":
            db.drop_tables(all_models)

        if p_state == "reset" or p_state == "migrate":
            try:
                db_uri = app.config["DB_URI"]
                runmigration.run_alembic_migration(db_uri,
                                                   logger,
                                                   setup_app=False)
            except Exception as ex:
                return (
                    {
                        "failed": True,
                        "msg": "Database migrations failed: %s" % ex
                    },
                    400,
                )
            changed = True

        # Always run 'present' state to confirm 'reset'
        tables = db.get_tables()
        extra_tables = list(set(expected_tables) - set(tables))
        missing_tables = list(set(tables) - set(expected_tables))
        if extra_tables != [] or missing_tables != []:
            return (
                {
                    "failed":
                    True,
                    "msg":
                    "Database exists but has mismatched tables\nMissing tables: %s\nExtra tables: %s"
                    % (missing_tables, extra_tables),
                },
                400,
            )

    return {"failed": False, "changed": changed, "meta": response}, 200
Exemplo n.º 3
0
from data.correctional_institutions import acquisition as correctional_institutions_acquisition
from data.counties import acquisition as counties_acquisition
from data.covid import acquisition as covid_acquisition
from data.nursing_homes import acquisition as nursing_home_acquisition
from data.covid import acquisition_ci_specific as covid_ci_acquisition
from data.covid import acquisition_nh_specific as covid_nh_acquisition
from data.demographics import acquisition as demographics_acquisition

LOGGING_LEVEL = logging.DEBUG
GOOGLE_API_KEY = settings.GOOGLE_API_KEY

if __name__ == "__main__":

    logging.basicConfig(level=logging.DEBUG)

    db.drop_tables()

    db.init_county_database()
    counties_acquisition.harvest()

    db.init_institution_database()
    correctional_institutions_acquisition.harvest(api_key=GOOGLE_API_KEY)

    db.init_covid_database()
    covid_acquisition.harvest()

    db.init_nursing_home_database()
    nursing_home_acquisition.harvest()

    db.init_institution_covid_database()
    covid_ci_acquisition.harvest()