-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Thomas Maschler
committed
Apr 15, 2020
1 parent
a6f554d
commit 40e4a6e
Showing
28 changed files
with
949 additions
and
359 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,8 @@ | ||
from fastapi import FastAPI | ||
from gino.ext.starlette import Gino | ||
from sentry_sdk import init as initialize_sentry | ||
from sentry_sdk.integrations.sqlalchemy import SqlalchemyIntegration | ||
from sqlalchemy.schema import MetaData | ||
|
||
from .settings.globals import DATABASE_CONFIG, SENTRY_DSN | ||
|
||
if SENTRY_DSN not in (None, ""): | ||
initialize_sentry(dsn=SENTRY_DSN, integrations=[SqlalchemyIntegration()]) | ||
from .settings.globals import DATABASE_CONFIG | ||
|
||
app: FastAPI = FastAPI() | ||
db: MetaData = Gino(app, dsn=DATABASE_CONFIG.url) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from .base import Base, db | ||
|
||
|
||
class Asset(Base): | ||
__tablename__ = 'assets' | ||
dataset = db.Column(db.String, primary_key=True) | ||
version = db.Column(db.String, primary_key=True) | ||
asset_type = db.Column(db.String, primary_key=True) | ||
asset_uri = db.Column(db.String) | ||
metadata = db.Column(db.JSONB) | ||
|
||
fk = db.ForeignKeyConstraint(["dataset", "version"], ["versions.dataset", "versions.version"], name="fk") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from .base import Base, db | ||
|
||
|
||
class Dataset(Base): | ||
__tablename__ = 'datasets' | ||
dataset = db.Column(db.String, primary_key=True) | ||
metadata = db.Column(db.JSONB) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from .base import Base, db | ||
|
||
|
||
class Geostore(Base): | ||
__tablename__ = 'geostore' | ||
|
||
gfw_geostore_id = db.Column(db.UUID, primary_key=True) | ||
gfw_geojson = db.Column(db.String, nullable=False), | ||
gfw_area__ha = db.Column(db.Numeric, nullable=False) | ||
gfw_bbox = db.Column(db.Geometry("Polygon", 4326), nullable=False) # TODO check if this is the correct type | ||
|
||
_geostore_gfw_geostore_id_idx = db.Index("geostore_gfw_geostore_id_idx", "gfw_geostore_id", postgresql_using='hash') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
"""empty message | ||
Revision ID: 86ae41de358d | ||
Revises: | ||
Create Date: 2020-04-14 21:58:38.173605 | ||
""" | ||
import json | ||
import os | ||
|
||
import boto3 | ||
import sqlalchemy as sa | ||
import geoalchemy2 | ||
|
||
from alembic import op | ||
from sqlalchemy.dialects import postgresql | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = 'e47ec2fc3c51' | ||
down_revision = None | ||
branch_labels = None | ||
depends_on = None | ||
|
||
client = boto3.client("secretsmanager") | ||
response = client.get_secret_value(SecretId=os.environ["SECRET_NAME"]) | ||
secrets = json.loads(response["SecretString"]) | ||
|
||
USERNAME = secrets["username"] | ||
PASSWORD = secrets["password"] | ||
DBNAME = secrets["dbname"] | ||
|
||
|
||
def upgrade(): | ||
|
||
#### Create read only user | ||
op.execute(f""" | ||
DO | ||
$do$ | ||
BEGIN | ||
IF NOT EXISTS ( | ||
SELECT -- SELECT list can stay empty for this | ||
FROM pg_catalog.pg_roles | ||
WHERE rolname = '{USERNAME}') THEN | ||
CREATE ROLE {USERNAME} LOGIN PASSWORD '{PASSWORD}'; | ||
END IF; | ||
END | ||
$do$; | ||
""") | ||
op.execute(f"GRANT CONNECT ON DATABASE {DBNAME} TO {USERNAME};") | ||
op.execute(f"ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO {USERNAME};") | ||
|
||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.create_table('datasets', | ||
sa.Column('created_on', sa.DateTime(), server_default=sa.text('now()'), nullable=True), | ||
sa.Column('updated_on', sa.DateTime(), server_default=sa.text('now()'), nullable=True), | ||
sa.Column('dataset', sa.String(), nullable=False), | ||
sa.Column('metadata', postgresql.JSONB(astext_type=sa.Text()), nullable=True), | ||
sa.PrimaryKeyConstraint('dataset') | ||
) | ||
op.create_table('geostore', | ||
sa.Column('created_on', sa.DateTime(), server_default=sa.text('now()'), nullable=True), | ||
sa.Column('updated_on', sa.DateTime(), server_default=sa.text('now()'), nullable=True), | ||
sa.Column('gfw_geostore_id', postgresql.UUID(), nullable=False), | ||
sa.Column('gfw_area__ha', sa.Numeric(), nullable=False), | ||
sa.Column('gfw_bbox', geoalchemy2.types.Geometry(geometry_type='POLYGON', srid=4326), nullable=False), | ||
sa.PrimaryKeyConstraint('gfw_geostore_id') | ||
) | ||
op.create_index('geostore_gfw_geostore_id_idx', 'geostore', ['gfw_geostore_id'], unique=False, postgresql_using='hash') | ||
op.create_table('versions', | ||
sa.Column('created_on', sa.DateTime(), server_default=sa.text('now()'), nullable=True), | ||
sa.Column('updated_on', sa.DateTime(), server_default=sa.text('now()'), nullable=True), | ||
sa.Column('dataset', sa.String(), nullable=False), | ||
sa.Column('version', sa.String(), nullable=False), | ||
sa.Column('is_latest', sa.Boolean(), nullable=True), | ||
sa.Column('source_type', sa.String(), nullable=False), | ||
sa.Column('has_vector_tile_cache', sa.Boolean(), nullable=True), | ||
sa.Column('has_raster_tile_cache', sa.Boolean(), nullable=True), | ||
sa.Column('has_geostore', sa.Boolean(), nullable=True), | ||
sa.Column('has_feature_info', sa.Boolean(), nullable=True), | ||
sa.Column('has_10_40000_tiles', sa.Boolean(), nullable=True), | ||
sa.Column('has_90_27008_tiles', sa.Boolean(), nullable=True), | ||
sa.Column('has_90_9876_tiles', sa.Boolean(), nullable=True), | ||
sa.Column('metadata', postgresql.JSONB(astext_type=sa.Text()), nullable=True), | ||
sa.ForeignKeyConstraint(['dataset'], ['datasets.dataset'], name='fk'), | ||
sa.PrimaryKeyConstraint('dataset', 'version') | ||
) | ||
op.create_table('assets', | ||
sa.Column('created_on', sa.DateTime(), server_default=sa.text('now()'), nullable=True), | ||
sa.Column('updated_on', sa.DateTime(), server_default=sa.text('now()'), nullable=True), | ||
sa.Column('dataset', sa.String(), nullable=False), | ||
sa.Column('version', sa.String(), nullable=False), | ||
sa.Column('asset_type', sa.String(), nullable=False), | ||
sa.Column('asset_uri', sa.String(), nullable=True), | ||
sa.Column('metadata', postgresql.JSONB(astext_type=sa.Text()), nullable=True), | ||
sa.ForeignKeyConstraint(['dataset', 'version'], ['versions.dataset', 'versions.version'], name='fk'), | ||
sa.PrimaryKeyConstraint('dataset', 'version', 'asset_type') | ||
) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_table('assets') | ||
op.drop_table('versions') | ||
op.drop_index('geostore_gfw_geostore_id_idx', table_name='geostore') | ||
op.drop_table('geostore') | ||
op.drop_table('datasets') | ||
# ### end Alembic commands ### |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from .base import Base, db | ||
|
||
|
||
class Version(Base): | ||
__tablename__ = 'versions' | ||
dataset = db.Column(db.String, primary_key=True) | ||
version = db.Column(db.String, primary_key=True) | ||
is_latest = db.Column(db.Boolean, default=False) | ||
source_type = db.Column(db.String, nullable=False) | ||
has_vector_tile_cache = db.Column(db.Boolean, default=False) | ||
has_raster_tile_cache = db.Column(db.Boolean, default=False) | ||
has_geostore = db.Column(db.Boolean, default=False) | ||
has_feature_info = db.Column(db.Boolean, default=False) | ||
has_10_40000_tiles = db.Column(db.Boolean, default=False) | ||
has_90_27008_tiles = db.Column(db.Boolean, default=False) | ||
has_90_9876_tiles = db.Column(db.Boolean, default=False) | ||
metadata = db.Column(db.JSONB) | ||
|
||
fk = db.ForeignKeyConstraint(["dataset"], ["datasets.dataset"], name="fk") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from fastapi import Path | ||
|
||
|
||
VERSION_REGEX = r"^v\d{1,8}\.?\d{1,3}\.?\d{1,3}$|^latest$" | ||
|
||
|
||
async def dataset_dependency(dataset: str = Path(..., title="Dataset")): | ||
return dataset | ||
|
||
|
||
async def version_dependency( | ||
version: str = Path(..., title="Dataset version", regex=VERSION_REGEX) | ||
): | ||
|
||
# if version == "latest": | ||
# version = ... | ||
|
||
return version |
Oops, something went wrong.