Esempio n. 1
0
 def _execute(self, cursor):
     dataset_id = uuid.uuid4()
     write(
         cursor,
         Dataset(self.hub_id, dataset_id, self.name,
                 dt.datetime.now(tz=pytz.utc), None))
     return dataset_id
Esempio n. 2
0
 def _execute(self, cursor):
     member_id = uuid.uuid4()
     write(
         cursor,
         TeamMember(member_id, self.team_id, self.user_id,
                    dt.datetime.now(tz=pytz.utc), None))
     return member_id
Esempio n. 3
0
 def _execute(self, cursor):
     user_id = uuid.uuid4()
     password_hash = security.pwd_context.hash(self.password)
     write(
         cursor,
         User(user_id, self.email, password_hash,
              dt.datetime.now(tz=pytz.utc)))
     return user_id
Esempio n. 4
0
 def _execute(self, cursor):
     connection_id = uuid.uuid4()
     write(
         cursor,
         Connection(connection_id, self.hub_id, self.dataset_id,
                    self.connector_id, self.path,
                    dt.datetime.now(tz=pytz.utc)))
     return connection_id
Esempio n. 5
0
 def _execute(self, cursor):
     partition_id = uuid.uuid4()
     write(
         cursor,
         Partition(partition_id, self.hub_id, self.dataset_id, self.version,
                   self.path, self.values, self.row_count, self.start_time,
                   self.end_time, dt.datetime.now(tz=pytz.utc), None))
     return partition_id
Esempio n. 6
0
    def _execute(self, cursor):
        created_at = dt.datetime.now(tz=pytz.utc)

        hub_id = uuid.uuid4()
        write(cursor, Hub(hub_id, self.team_id, self.name, created_at))

        team_role_id = uuid.uuid4()
        write(
            cursor,
            TeamRole(team_role_id, self.team_id, hub_id,
                     AccessLevel.ADMIN.value, created_at))

        return hub_id
Esempio n. 7
0
    def _execute(self, cursor):
        cursor.execute(
            '''
            SELECT max(version)
            FROM dataset_versions
            WHERE
                hub_id = %s
            AND dataset_id = %s
        ''', (self.hub_id, self.dataset_id))
        latest_version = cursor.fetchone()[0] or 0

        write(
            cursor,
            DatasetVersion(self.hub_id, self.dataset_id, latest_version + 1,
                           Backend.by_module(self.backend).id, self.path,
                           self.partition_keys, self.description,
                           self.is_overlapping, dt.datetime.now(tz=pytz.utc)))

        position = 0
        for column in self.columns:
            name, type_name, description, is_nullable, is_unique, has_pii = column
            write(
                cursor,
                Column(self.hub_id, self.dataset_id, latest_version + 1, name,
                       Type.by_name(type_name).id, position, description,
                       is_nullable, is_unique, has_pii))
            position += 1

        for (parent_hub_id, parent_dataset_id,
             parent_version) in self.depends_on:
            write(
                cursor,
                Dependency(parent_hub_id, parent_dataset_id, parent_version,
                           self.hub_id, self.dataset_id, latest_version + 1))

        return latest_version + 1
Esempio n. 8
0
 def _execute(self, cursor):
     team_id = uuid.uuid4()
     write(cursor, Team(team_id, self.name, dt.datetime.now(tz=pytz.utc)))
     return team_id
Esempio n. 9
0
 def _execute(self, cursor):
     write(
         cursor,
         PublishedVersion(self.hub_id, self.dataset_id, self.version,
                          dt.datetime.now(tz=pytz.utc)))
Esempio n. 10
0
psql.extras.register_uuid()


def truncate(cursor, kind):
    cursor.execute(f'TRUNCATE TABLE {kind.table_name} CASCADE')


if __name__ == '__main__':
    conn = psql.connect('')
    pq.PQ(conn=conn).create()

    cursor = conn.cursor()

    for kind in [
            Hub, Dataset, Backend, DatasetVersion, PublishedVersion, Type,
            Column, Partition
    ]:
        truncate(cursor, kind)

    for entry in Types:
        write(cursor, entry)

    for entry in Backends:
        write(cursor, entry)

    for entry in Connectors:
        write(cursor, entry)

    conn.commit()