Skip to content

Commit

Permalink
api version 2
Browse files Browse the repository at this point in the history
  • Loading branch information
Maneesh7012 committed Sep 16, 2023
1 parent ae40513 commit 4c7234d
Show file tree
Hide file tree
Showing 114 changed files with 7,167 additions and 2,338 deletions.
135 changes: 0 additions & 135 deletions src/api/.gitignore

This file was deleted.

15 changes: 15 additions & 0 deletions src/api/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM osgeo/gdal:ubuntu-small-3.2.0

RUN apt-get update
RUN apt-get -y install python3-pip
RUN pip install rasterstats
RUN pip uninstall fastapi python-multipart
RUN pip install fastapi python-multipart

WORKDIR /app

COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
EXPOSE 8000
# CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]
99 changes: 0 additions & 99 deletions src/api/README.md

This file was deleted.

22 changes: 16 additions & 6 deletions src/api/alembic.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
# path to migration scripts
script_location = alembic

# template used to generate migration files
# file_template = %%(rev)s_%%(slug)s
# template used to generate migration file names; The default value is %%(rev)s_%%(slug)s
# Uncomment the line below if you want the files to be prepended with date and time
# see https://alembic.sqlalchemy.org/en/latest/tutorial.html#editing-the-ini-file
# for all available tokens
# file_template = %%(year)d_%%(month).2d_%%(day).2d_%%(hour).2d%%(minute).2d-%%(rev)s_%%(slug)s

# sys.path path, will be prepended to sys.path if present.
# defaults to the current working directory.
Expand Down Expand Up @@ -35,22 +38,29 @@ prepend_sys_path = .
# version location specification; This defaults
# to alembic/versions. When using multiple version
# directories, initial revisions must be specified with --version-path.
# The path separator used here should be the separator specified by "version_path_separator"
# The path separator used here should be the separator specified by "version_path_separator" below.
# version_locations = %(here)s/bar:%(here)s/bat:alembic/versions

# version path separator; As mentioned above, this is the character used to split
# version_locations. Valid values are:
# version_locations. The default within new alembic.ini files is "os", which uses os.pathsep.
# If this key is omitted entirely, it falls back to the legacy behavior of splitting on spaces and/or commas.
# Valid values for version_path_separator are:
#
# version_path_separator = :
# version_path_separator = ;
# version_path_separator = space
version_path_separator = os # default: use os.pathsep
version_path_separator = os # Use os.pathsep. Default configuration used for new projects.

# set to 'true' to search source files recursively
# in each "version_locations" directory
# new in Alembic version 1.10
# recursive_version_locations = false

# the output encoding used when revision files
# are written from script.py.mako
# output_encoding = utf-8

sqlalchemy.url = postgresql://uname:password@host/database
sqlalchemy.url = driver://user:pass@localhost/dbname


[post_write_hooks]
Expand Down
12 changes: 7 additions & 5 deletions src/api/alembic/env.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
from logging.config import fileConfig

from sqlalchemy import engine_from_config
from sqlalchemy import pool

from alembic import context
from app.config.config import settings

# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
config = context.config

config.set_main_option('sqlalchemy.url', settings.POSTGRES_CONNECTION_STRING)
# Interpret the config file for Python logging.
# This line sets up loggers basically.
fileConfig(config.config_file_name)
if config.config_file_name is not None:
fileConfig(config.config_file_name)

# add your model's MetaData object here
# for 'autogenerate' support
Expand All @@ -25,7 +27,7 @@
# ... etc.


def run_migrations_offline():
def run_migrations_offline() -> None:
"""Run migrations in 'offline' mode.
This configures the context with just a URL
Expand All @@ -49,15 +51,15 @@ def run_migrations_offline():
context.run_migrations()


def run_migrations_online():
def run_migrations_online() -> None:
"""Run migrations in 'online' mode.
In this scenario we need to create an Engine
and associate a connection with the context.
"""
connectable = engine_from_config(
config.get_section(config.config_ini_section),
config.get_section(config.config_ini_section, {}),
prefix="sqlalchemy.",
poolclass=pool.NullPool,
)
Expand Down
4 changes: 2 additions & 2 deletions src/api/alembic/script.py.mako
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ branch_labels = ${repr(branch_labels)}
depends_on = ${repr(depends_on)}


def upgrade():
def upgrade() -> None:
${upgrades if upgrades else "pass"}


def downgrade():
def downgrade() -> None:
${downgrades if downgrades else "pass"}
29 changes: 29 additions & 0 deletions src/api/alembic/versions/0270e53bf5f9_create_region_table.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""Create region table
Revision ID: 0270e53bf5f9
Revises:
Create Date: 2023-04-07 02:53:03.704691
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '0270e53bf5f9'
down_revision = None
branch_labels = None
depends_on = None


def upgrade() -> None:
op.create_table(
'regions',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=50), nullable=False),
sa.PrimaryKeyConstraint('id')
)


def downgrade() -> None:
op.drop_table('layers')
Loading

0 comments on commit 4c7234d

Please sign in to comment.