diff --git a/docker-compose.deploy.yml b/docker-compose.deploy.yml index 3e07fb70ec..60b912a2ec 100644 --- a/docker-compose.deploy.yml +++ b/docker-compose.deploy.yml @@ -91,6 +91,7 @@ services: - fmtm_tiles:/opt/tiles depends_on: - fmtm-db + - migrations - traefik env_file: - .env @@ -109,13 +110,12 @@ services: image: "ghcr.io/hotosm/fmtm/backend:${API_VERSION}-${GIT_BRANCH}" container_name: fmtm_migrations depends_on: - - api + - fmtm-db env_file: - .env networks: - fmtm-net entrypoint: ["/migrate-entrypoint.sh"] - command: ["alembic", "upgrade", "head"] restart: "on-failure:3" ui: diff --git a/docker-compose.noodk.yml b/docker-compose.noodk.yml index bbbca5a2b8..8eb2131ca6 100644 --- a/docker-compose.noodk.yml +++ b/docker-compose.noodk.yml @@ -58,6 +58,7 @@ services: - ./src/backend/app:/opt/app depends_on: - fmtm-db + - migrations env_file: - .env ports: @@ -71,13 +72,12 @@ services: image: "ghcr.io/hotosm/fmtm/backend:${API_VERSION}-${GIT_BRANCH}" container_name: fmtm_migrations depends_on: - - api + - fmtm-db env_file: - .env networks: - fmtm-net entrypoint: ["/migrate-entrypoint.sh"] - command: ["alembic", "upgrade", "head"] restart: "on-failure:3" ui: diff --git a/docker-compose.yml b/docker-compose.yml index ca5359ef26..5e52d9aca6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -64,6 +64,7 @@ services: # - ../osm-fieldwork/osm_fieldwork:/home/appuser/.local/lib/python3.10/site-packages/osm_fieldwork depends_on: - fmtm-db + - migrations - central-proxy env_file: - .env @@ -78,13 +79,12 @@ services: image: "ghcr.io/hotosm/fmtm/backend:debug" container_name: fmtm_migrations depends_on: - - api + - fmtm-db env_file: - .env networks: - fmtm-dev entrypoint: ["/migrate-entrypoint.sh"] - command: ["alembic", "upgrade", "head"] restart: "on-failure:3" ui: diff --git a/docs/dev/Database-Tips.md b/docs/dev/Database-Tips.md index 0ccbd8b66e..37eeab4539 100644 --- a/docs/dev/Database-Tips.md +++ b/docs/dev/Database-Tips.md @@ -1,122 +1,196 @@ -# Access the database (psql) +# Database Tips -**Option 1** (when the docker container is running) use this command to access it through the local psql using the below command: +## Access the database (psql) - `psql -d fmtm -U fmtm -h localhost` +### Option 1 -**Option 2** (when running the database in Docker) use this command to access the -PostgreSQL shell inside the fmtm-db-1 container and interact with the fmtm database -using the psql command-line interface: +Access the database container using psql on your local machine: - `docker exec -it fmtm-db-1 psql -U fmtm fmtm` +```bash +psql -d fmtm -U fmtm -h localhost +``` -And then connect to the database using this command : +### Option 2 - `\c fmtm` +Access a PostgreSQL shell inside the fmtm_db container: -## To access the fmtm database using psql, follow the instructions below +```bash +docker exec -it fmtm_db psql -U fmtm fmtm +``` -### A few helpful psql commands +And then connect to the database using this command: -- Open a terminal window and run the following command: +```bash +\c fmtm +``` - docker exec -it fmtm-db-1 psql -U fmtm fmtm - - This will open the psql command-line interface and connect you to the fmtm database. - -- Once connected to the fmtm database, you can switch to a different database using the command: - - \c dbname - - Replace "dbname" with the name of the database you want to switch to. forexample `\c fmtm` +## A few helpful psql commands - You can list all the databases using the command: - \l +```bash +\l +``` - To list all the schemas of the currently connected database, use the command: - \dn +```bash +\dn +``` - To list all the functions in the current database, use the command: - \df +```bash +\df +``` - To list all the views in the current database, use the command: - \dv +```bash +\dv +``` - To list all the users and roles, use the command: - \du +```bash +\du +``` - To list all the tables in the current database, use the command: - \dt +```bash +\dt +``` - To describe a table, use the command: - \d table_name +```bash +\d table_name +``` - Replace "table_name" with the name of the table you want to describe. +Replace "table_name" with the name of the table you want to describe. - To execute the last command again, use the command: - \g +```bash +\g +``` - To view your command history, use the command: - \s +```bash +\s +``` - To save your command history to a file, use the command: - \s filename +```bash +\s filename +``` - Replace "filename" with the name of the file you want to save the command history to. +Replace "filename" with the name of the file you +want to save the command history to. - To execute commands from a file, use the command: - \i filename +```bash +\i filename +``` - Replace "filename" with the name of the file containing the commands you want to execute. +Replace "filename" with the name of the file +containing the commands you want to execute. - To view a list of all psql commands, use the command: - \? +```bash +\? +``` - To view help for a specific command, use the command: - \h command_name +```bash +\h command_name +``` - Replace "command_name" with the name of the command you want help with. +Replace "command_name" with the name of the command you want help with. - To exit psql, use the command: - \q +```bash +\q +``` **Note:** If you make a change, don't forget to commit the change! -# Migrations - -Migrations are a way to manage changes to the database schema over time. We haven't yet implemented migrations in fmtm, but if you need to drop all tables, you can use the following commands while connected to the fmtm database: - -If you need to drop all tables, connect to fmtm and... - - drop table mapping_issue_categories cascade; - drop table organisation_managers cascade; - drop table organisations cascade; - drop table project_allowed_users cascade; - drop table project_chat cascade; - drop table project_info cascade; - drop table project_teams cascade; - drop table projects cascade; - drop table task_history cascade; - drop table task_invalidation_history cascade; - drop table task_mapping_issues cascade; - drop table tasks cascade; - drop table teams cascade; - drop table user_licenses cascade; - drop table users cascade; - drop table x_form cascade; - -**Note:** Remember to use caution when dropping tables, as this will permanently delete all data in those tables. If you make any changes to the database, be sure to commit them to ensure that they are saved. +## Migrations + +- Migrations are a way to manage changes to the database schema over time. +- They are handled automatically by a management script when FMTM starts up. +- Individual SQL migration scripts are placed in the `src/backend/migrations` dir. + - These should be idempotent, i.e. can run over and over without causing errors. + - There should also be a commented out SQL script for how to revert the migration. + - Scripts should be named sequentially, + i.e. the first is 001-some-migration.sql, + then they increment by one. + - Example `000-remove-user-password.sql`: + +```bash +-- ## Migration to remove password field from public.users (replaced with OSM OAuth) + + +-- ## Apply Migration +-- Start a transaction +BEGIN; +-- Drop the 'password' column if it exists +ALTER TABLE IF EXISTS public.users +DROP COLUMN IF EXISTS password; +-- Commit the transaction +COMMIT; + + +-- ## Revert Migration (comment above, uncomment below) +-- -- Start a transaction +-- BEGIN; +-- -- Add the 'password' column back if it doesn't exist +-- ALTER TABLE public.users +-- ADD COLUMN IF NOT EXISTS password character varying; +-- -- Commit the transaction +-- COMMIT; +``` + +- When the docker compose stack starts, + an additional container starts up and runs a bash script once. +- The script generates a _table_ called `migrations`, + which simply tracks the script name and execution date. +- The `migrations` _directory_ is scanned for new files, + and if there is no record in the database of being applied, + the migration is applied. + +### Running Migrations Manually + +If for any reason you need to run migrations manually, +there are a few options: + +#### Restart the migrations container + +```bash +docker compose restart migrations +``` + +#### Run the migration script in docker + +This runs inside the backend container: + +```bash +docker compose exec api bash /migrate-entrypoint.sh` +``` + +#### Run the migration script directly + +Make sure you have the 4 env vars for the database +connection set on your machine, +then run the migration script directly: + +```bash +bash src/backend/migrate-entrypoint.sh +``` diff --git a/src/backend/.dockerignore b/src/backend/.dockerignore index 0be5300a90..2a9161252e 100644 --- a/src/backend/.dockerignore +++ b/src/backend/.dockerignore @@ -10,4 +10,3 @@ !pyproject.toml !pdm.lock !migrations -!alembic.ini diff --git a/src/backend/Dockerfile b/src/backend/Dockerfile index f80472bba2..31416e7f74 100644 --- a/src/backend/Dockerfile +++ b/src/backend/Dockerfile @@ -108,7 +108,6 @@ WORKDIR /opt # Add app code COPY app/ /opt/app/ COPY migrations/ /opt/migrations/ -COPY alembic.ini /opt/ # Add non-root user, permissions RUN useradd -r -u 1001 -m -c "hotosm account" -d /home/appuser -s /bin/false appuser \ && mkdir -p /opt/logs /opt/tiles \ @@ -150,23 +149,24 @@ USER appuser FROM runtime as ci # Run all ci as root USER root -ENV PATH="/root/.local/bin:$PATH" -RUN set -ex \ +ARG PYTHON_IMG_TAG +COPY --from=extract-deps \ + /opt/python/requirements-ci.txt /opt/python/ +RUN mv /home/appuser/.local/bin/* /usr/local/bin/ \ + && mv /home/appuser/.local/lib/python${PYTHON_IMG_TAG}/site-packages/* \ + /usr/local/lib/python${PYTHON_IMG_TAG}/site-packages/ \ + && set -ex \ && apt-get update \ && DEBIAN_FRONTEND=noninteractive apt-get install \ -y --no-install-recommends \ - "gosu" \ "git" \ - && rm -rf /var/lib/apt/lists/* -RUN mv /home/appuser/.local /root/.local -COPY --from=extract-deps \ - /opt/python/requirements-ci.txt /opt/python/ -RUN pip install --user --upgrade --no-warn-script-location \ + && rm -rf /var/lib/apt/lists/* \ + && pip install --upgrade --no-warn-script-location \ --no-cache-dir -r \ /opt/python/requirements-ci.txt \ - && rm -r /opt/python -# Pre-compile packages to .pyc (init speed gains) -RUN python -c "import compileall; compileall.compile_path(maxlevels=10, quiet=1)" + && rm -r /opt/python \ + # Pre-compile packages to .pyc (init speed gains) + && python -c "import compileall; compileall.compile_path(maxlevels=10, quiet=1)" # Override entrypoint, as not possible in Github action ENTRYPOINT [""] CMD [""] diff --git a/src/backend/alembic.ini b/src/backend/alembic.ini deleted file mode 100644 index b2c14b0b03..0000000000 --- a/src/backend/alembic.ini +++ /dev/null @@ -1,113 +0,0 @@ -# A generic, single database configuration. - -[alembic] -# path to migration scripts -script_location = migrations - -# 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. -prepend_sys_path = . - -# timezone to use when rendering the date within the migration file -# as well as the filename. -# If specified, requires the python-dateutil library that can be -# installed by adding `alembic[tz]` to the pip requirements -# string value is passed to dateutil.tz.gettz() -# leave blank for localtime -# timezone = - -# max length of characters to apply to the -# "slug" field -# truncate_slug_length = 40 - -# set to 'true' to run the environment during -# the 'revision' command, regardless of autogenerate -# revision_environment = false - -# set to 'true' to allow .pyc and .pyo files without -# a source .py file to be detected as revisions in the -# versions/ directory -# sourceless = false - -# version location specification; This defaults -# to migrations/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" below. -# version_locations = %(here)s/bar:%(here)s/bat:migrations/versions - -# version path separator; As mentioned above, this is the character used to split -# 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 # 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 = - -[post_write_hooks] -# post_write_hooks defines scripts or Python functions that are run -# on newly generated revision scripts. See the documentation for further -# detail and examples - -# format using "black" - use the console_scripts runner, against the "black" entrypoint -# hooks = black -# black.type = console_scripts -# black.entrypoint = black -# black.options = -l 79 REVISION_SCRIPT_FILENAME - -# Custom param that enables us to specify tables to ignore when determining migrations -[alembic:exclude] -tables = spatial_ref_sys - -# Logging configuration -[loggers] -keys = root,sqlalchemy,alembic - -[handlers] -keys = console - -[formatters] -keys = generic - -[logger_root] -level = WARN -handlers = console -qualname = - -[logger_sqlalchemy] -level = WARN -handlers = -qualname = sqlalchemy.engine - -[logger_alembic] -level = INFO -handlers = -qualname = alembic - -[handler_console] -class = StreamHandler -args = (sys.stderr,) -level = NOTSET -formatter = generic - -[formatter_generic] -format = "%(asctime)s.%(msecs)03d [%(levelname)s] %(name)s | %(funcName)s:%(lineno)d | %(message)s" -datefmt = "%y-%m-%d %H:%M:%S" diff --git a/src/backend/app-entrypoint.sh b/src/backend/app-entrypoint.sh index 75cceb7b00..259e74c550 100644 --- a/src/backend/app-entrypoint.sh +++ b/src/backend/app-entrypoint.sh @@ -2,9 +2,22 @@ set -eo pipefail -while !. # +"""SQLAlchemy database models for interacting with Postgresql.""" from geoalchemy2 import Geometry from sqlalchemy import ( @@ -100,9 +101,6 @@ class DbUser(Base): # Represents the date the user last had one of their tasks validated last_validation_date = Column(DateTime, default=timestamp) - # TODO: This changes to use Oath - password = Column(String) - # Secondary table defining many-to-many relationship between organisations and managers organisation_managers = Table( @@ -158,7 +156,8 @@ class DbTeam(Base): organisation = relationship(DbOrganisation, backref="teams") -# Secondary table defining many-to-many join for private projects that only defined users can map on +# Secondary table defining many-to-many join for +# private projects that only defined users can map on project_allowed_users = Table( "project_allowed_users", FmtmMetadata, @@ -168,6 +167,8 @@ class DbTeam(Base): class DbProjectTeams(Base): + """Link table between teams and projects.""" + __tablename__ = "project_teams" team_id = Column(Integer, ForeignKey("teams.id"), primary_key=True) project_id = Column(Integer, ForeignKey("projects.id"), primary_key=True) @@ -231,7 +232,10 @@ class DbXForm(Base): class DbTaskInvalidationHistory(Base): - """Describes the most recent history of task invalidation and subsequent validation.""" + """Information on task invalidation. + + Describes the most recent history of task invalidation and subsequent validation. + """ __tablename__ = "task_invalidation_history" id = Column(Integer, primary_key=True) @@ -265,9 +269,10 @@ class DbTaskInvalidationHistory(Base): class DbTaskMappingIssue(Base): - """Describes an issue (along with an occurrence count) with a - task mapping that contributed to invalidation of the task - . + """Describes mapping issues. + + An issue (along with an occurrence count) with a + task mapping that contributed to invalidation of the task. """ __tablename__ = "task_mapping_issues" @@ -382,7 +387,8 @@ class DbTask(Base): # y = Column(Integer) # zoom = Column(Integer) # extra_properties = Column(Unicode) - # # Tasks need to be split differently if created from an arbitrary grid or were clipped to the edge of the AOI + # # Tasks need to be split differently if created from an arbitrary grid + # or were clipped to the edge of the AOI # is_square = Column(Boolean, default=False) @@ -439,6 +445,7 @@ class DbProject(Base): @property def tasks_mapped(self): + """Get the number of tasks mapped for a project.""" return ( object_session(self) .query(DbTask) @@ -449,6 +456,7 @@ def tasks_mapped(self): @property def tasks_validated(self): + """Get the number of tasks validated for a project.""" return ( object_session(self) .query(DbTask) @@ -459,6 +467,7 @@ def tasks_validated(self): @property def tasks_bad(self): + """Get the number of tasks marked bad for a project.""" return ( object_session(self) .query(DbTask) @@ -590,6 +599,8 @@ class DbFeatures(Base): class BackgroundTasks(Base): + """Table managing long running background tasks.""" + __tablename__ = "background_tasks" id = Column(String, primary_key=True) @@ -600,6 +611,8 @@ class BackgroundTasks(Base): class DbUserRoles(Base): + """Fine grained user control for projects, described by roles.""" + __tablename__ = "user_roles" user_id = Column(BigInteger, ForeignKey("users.id"), primary_key=True) @@ -612,6 +625,8 @@ class DbUserRoles(Base): class DbProjectAOI(Base): + """The AOI geometry for a project.""" + __tablename__ = "project_aoi" id = Column(Integer, primary_key=True) @@ -621,6 +636,8 @@ class DbProjectAOI(Base): class DbOsmLines(Base): + """Associated OSM ways for a project.""" + __tablename__ = "ways_line" id = Column(Integer, primary_key=True) @@ -630,6 +647,8 @@ class DbOsmLines(Base): class DbBuildings(Base): + """Associated OSM buildings for a project.""" + __tablename__ = "ways_poly" id = Column(Integer, primary_key=True) @@ -640,6 +659,8 @@ class DbBuildings(Base): class DbTilesPath(Base): + """Keeping track of mbtile basemaps for a project.""" + __tablename__ = "mbtiles_path" id = Column(Integer, primary_key=True) diff --git a/src/backend/migrate-entrypoint.sh b/src/backend/migrate-entrypoint.sh index ad8aba40b7..6923803f01 100644 --- a/src/backend/migrate-entrypoint.sh +++ b/src/backend/migrate-entrypoint.sh @@ -2,35 +2,208 @@ set -eo pipefail -while ! None: - """Run migrations in 'offline' mode. - - This configures the context with just a URL - and not an Engine, though an Engine is acceptable - here as well. By skipping the Engine creation - we don't even need a DBAPI to be available. - - Calls to context.execute() here emit the given string to the - script output. - - """ - log.info("Running offline migrations") - - url = config.get_main_option("sqlalchemy.url") - context.configure( - url=url, - include_object=include_object, - target_metadata=target_metadata, - literal_binds=True, - dialect_opts={"paramstyle": "named"}, - ) - - with context.begin_transaction(): - context.run_migrations() - log.info("Complete offline migrations") - - -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. - - """ - log.info("Running online migrations") - - connectable = engine_from_config( - config.get_section(config.config_ini_section), - prefix="sqlalchemy.", - poolclass=pool.NullPool, - ) - - with connectable.connect() as connection: - context.configure( - connection=connection, - include_object=include_object, - target_metadata=target_metadata, - ) - - with context.begin_transaction(): - context.run_migrations() - - log.info("Complete online migrations") - - -if context.is_offline_mode(): - run_migrations_offline() -else: - run_migrations_online() diff --git a/src/backend/migrations/init/fmtm_base_schema.sql b/src/backend/migrations/init/fmtm_base_schema.sql new file mode 100644 index 0000000000..e8354d16be --- /dev/null +++ b/src/backend/migrations/init/fmtm_base_schema.sql @@ -0,0 +1,992 @@ +-- +-- PostgreSQL database dump +-- + +-- Dumped from database version 14.9 +-- Dumped by pg_dump version 15.3 (Debian 15.3-0+deb12u1) + +-- Started on 2023-10-05 12:55:27 UTC + + +-- Setup + +SET statement_timeout = 0; +SET lock_timeout = 0; +SET idle_in_transaction_session_timeout = 0; +SET client_encoding = 'UTF8'; +SET standard_conforming_strings = on; +SELECT pg_catalog.set_config('search_path', '', false); +SET check_function_bodies = false; +SET xmloption = content; +SET client_min_messages = warning; +SET row_security = off; + +ALTER SCHEMA public OWNER TO fmtm; + + +-- PostGIS + +CREATE SCHEMA tiger; +ALTER SCHEMA tiger OWNER TO fmtm; + +CREATE SCHEMA tiger_data; +ALTER SCHEMA tiger_data OWNER TO fmtm; + +CREATE SCHEMA topology; +ALTER SCHEMA topology OWNER TO fmtm; + +CREATE EXTENSION IF NOT EXISTS fuzzystrmatch WITH SCHEMA public; +CREATE EXTENSION IF NOT EXISTS postgis WITH SCHEMA public; +CREATE EXTENSION IF NOT EXISTS postgis_tiger_geocoder WITH SCHEMA tiger; +CREATE EXTENSION IF NOT EXISTS postgis_topology WITH SCHEMA topology; + + +-- Enums + +CREATE TYPE public.backgroundtaskstatus AS ENUM ( + 'PENDING', + 'FAILED', + 'RECEIVED', + 'SUCCESS' +); +ALTER TYPE public.backgroundtaskstatus OWNER TO fmtm; + +CREATE TYPE public.mappinglevel AS ENUM ( + 'BEGINNER', + 'INTERMEDIATE', + 'ADVANCED' +); +ALTER TYPE public.mappinglevel OWNER TO fmtm; + +CREATE TYPE public.mappingpermission AS ENUM ( + 'ANY', + 'LEVEL', + 'TEAMS', + 'TEAMS_LEVEL' +); +ALTER TYPE public.mappingpermission OWNER TO fmtm; + +CREATE TYPE public.organisationtype AS ENUM ( + 'FREE', + 'DISCOUNTED', + 'FULL_FEE' +); +ALTER TYPE public.organisationtype OWNER TO fmtm; + +CREATE TYPE public.projectpriority AS ENUM ( + 'URGENT', + 'HIGH', + 'MEDIUM', + 'LOW' +); +ALTER TYPE public.projectpriority OWNER TO fmtm; + +CREATE TYPE public.projectstatus AS ENUM ( + 'ARCHIVED', + 'PUBLISHED', + 'DRAFT' +); +ALTER TYPE public.projectstatus OWNER TO fmtm; + +CREATE TYPE public.taskaction AS ENUM ( + 'RELEASED_FOR_MAPPING', + 'LOCKED_FOR_MAPPING', + 'MARKED_MAPPED', + 'LOCKED_FOR_VALIDATION', + 'VALIDATED', + 'MARKED_INVALID', + 'MARKED_BAD', + 'SPLIT_NEEDED', + 'RECREATED', + 'COMMENT' +); +ALTER TYPE public.taskaction OWNER TO fmtm; + +CREATE TYPE public.taskcreationmode AS ENUM ( + 'GRID', + 'ROADS', + 'UPLOAD' +); +ALTER TYPE public.taskcreationmode OWNER TO fmtm; + +CREATE TYPE public.taskstatus AS ENUM ( + 'READY', + 'LOCKED_FOR_MAPPING', + 'MAPPED', + 'LOCKED_FOR_VALIDATION', + 'VALIDATED', + 'INVALIDATED', + 'BAD', + 'SPLIT', + 'ARCHIVED' +); +ALTER TYPE public.taskstatus OWNER TO fmtm; + +CREATE TYPE public.teamvisibility AS ENUM ( + 'PUBLIC', + 'PRIVATE' +); +ALTER TYPE public.teamvisibility OWNER TO fmtm; + +CREATE TYPE public.userrole AS ENUM ( + 'MAPPER', + 'ADMIN', + 'VALIDATOR', + 'FIELD_ADMIN', + 'ORGANIZATION_ADMIN', + 'READ_ONLY' +); +ALTER TYPE public.userrole OWNER TO fmtm; + +CREATE TYPE public.validationpermission AS ENUM ( + 'ANY', + 'LEVEL', + 'TEAMS', + 'TEAMS_LEVEL' +); +ALTER TYPE public.validationpermission OWNER TO fmtm; + + +-- Extra + +SET default_tablespace = ''; +SET default_table_access_method = heap; + + +-- Tables + +CREATE TABLE IF NOT EXISTS public."_migrations" ( + date_executed TIMESTAMP, + script_name TEXT +); +ALTER TABLE public."_migrations" OWNER TO fmtm; + + +CREATE TABLE public.background_tasks ( + id character varying NOT NULL, + name character varying, + project_id integer, + status public.backgroundtaskstatus NOT NULL, + message character varying +); +ALTER TABLE public.background_tasks OWNER TO fmtm; + + +CREATE TABLE public.buildings ( + id integer, + project_id character varying, + osm_id character varying, + geom public.geometry(Polygon,4326), + tags jsonb, + polyid bigint +); +ALTER TABLE public.buildings OWNER TO fmtm; + + +CREATE TABLE public.clusteredbuildings ( + id integer, + project_id character varying, + osm_id character varying, + geom public.geometry(Polygon,4326), + tags jsonb, + polyid bigint, + numfeatures bigint, + cid integer, + clusteruid text +); +ALTER TABLE public.clusteredbuildings OWNER TO fmtm; + + +CREATE TABLE public.dumpedpoints ( + osm_id character varying, + polyid bigint, + cid integer, + clusteruid text, + geom public.geometry(Point,4326) +); +ALTER TABLE public.dumpedpoints OWNER TO fmtm; + + +CREATE TABLE public.features ( + id integer NOT NULL, + project_id integer, + category_title character varying, + task_id integer, + properties jsonb, + geometry public.geometry(Geometry,4326) +); +ALTER TABLE public.features OWNER TO fmtm; +CREATE SEQUENCE public.features_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; +ALTER TABLE public.features_id_seq OWNER TO fmtm; +ALTER SEQUENCE public.features_id_seq OWNED BY public.features.id; + + +CREATE TABLE public.licenses ( + id integer NOT NULL, + name character varying, + description character varying, + plain_text character varying +); +ALTER TABLE public.licenses OWNER TO fmtm; +CREATE SEQUENCE public.licenses_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; +ALTER TABLE public.licenses_id_seq OWNER TO fmtm; +ALTER SEQUENCE public.licenses_id_seq OWNED BY public.licenses.id; + + +CREATE TABLE public.lowfeaturecountpolygons ( + polyid bigint NOT NULL, + geom public.geometry(Polygon,4326), + geog public.geography(Geometry,4326), + numfeatures bigint, + area double precision, + n_polyid bigint, + n_area double precision, + n_numfeatures bigint, + sharedbound double precision +); +ALTER TABLE public.lowfeaturecountpolygons OWNER TO fmtm; + + +CREATE TABLE public.mapping_issue_categories ( + id integer NOT NULL, + name character varying NOT NULL, + description character varying, + archived boolean NOT NULL +); +ALTER TABLE public.mapping_issue_categories OWNER TO fmtm; +CREATE SEQUENCE public.mapping_issue_categories_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; +ALTER TABLE public.mapping_issue_categories_id_seq OWNER TO fmtm; +ALTER SEQUENCE public.mapping_issue_categories_id_seq OWNED BY public.mapping_issue_categories.id; + + +CREATE TABLE public.mbtiles_path ( + id integer NOT NULL, + project_id integer, + status public.backgroundtaskstatus NOT NULL, + path character varying, + tile_source character varying, + background_task_id character varying, + created_at timestamp without time zone +); +ALTER TABLE public.mbtiles_path OWNER TO fmtm; +CREATE SEQUENCE public.mbtiles_path_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; +ALTER TABLE public.mbtiles_path_id_seq OWNER TO fmtm; +ALTER SEQUENCE public.mbtiles_path_id_seq OWNED BY public.mbtiles_path.id; + + +CREATE TABLE public."_migrations" ( + script_name text, + date_executed timestamp without time zone +); +ALTER TABLE public."_migrations" OWNER TO fmtm; + + +CREATE TABLE public.organisation_managers ( + organisation_id integer NOT NULL, + user_id bigint NOT NULL +); +ALTER TABLE public.organisation_managers OWNER TO fmtm; + + +CREATE TABLE public.organisations ( + id integer NOT NULL, + name character varying(512) NOT NULL, + slug character varying(255) NOT NULL, + logo character varying, + description character varying, + url character varying, + type public.organisationtype NOT NULL +); +ALTER TABLE public.organisations OWNER TO fmtm; +CREATE SEQUENCE public.organisations_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; +ALTER TABLE public.organisations_id_seq OWNER TO fmtm; +ALTER SEQUENCE public.organisations_id_seq OWNED BY public.organisations.id; + + +CREATE TABLE public.project_allowed_users ( + project_id integer, + user_id bigint +); +ALTER TABLE public.project_allowed_users OWNER TO fmtm; + + +CREATE TABLE public.project_aoi ( + id integer NOT NULL, + project_id character varying, + geom public.geometry(Geometry,4326), + tags jsonb +); +ALTER TABLE public.project_aoi OWNER TO fmtm; +CREATE SEQUENCE public.project_aoi_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; +ALTER TABLE public.project_aoi_id_seq OWNER TO fmtm; +ALTER SEQUENCE public.project_aoi_id_seq OWNED BY public.project_aoi.id; + + +CREATE TABLE public.project_chat ( + id bigint NOT NULL, + project_id integer NOT NULL, + user_id integer NOT NULL, + time_stamp timestamp without time zone NOT NULL, + message character varying NOT NULL +); +ALTER TABLE public.project_chat OWNER TO fmtm; +CREATE SEQUENCE public.project_chat_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; +ALTER TABLE public.project_chat_id_seq OWNER TO fmtm; +ALTER SEQUENCE public.project_chat_id_seq OWNED BY public.project_chat.id; + + +CREATE TABLE public.project_info ( + project_id integer NOT NULL, + project_id_str character varying, + name character varying(512), + short_description character varying, + description character varying, + text_searchable tsvector, + per_task_instructions character varying +); +ALTER TABLE public.project_info OWNER TO fmtm; + + +CREATE TABLE public.project_teams ( + team_id integer NOT NULL, + project_id integer NOT NULL, + role integer NOT NULL +); +ALTER TABLE public.project_teams OWNER TO fmtm; + + +CREATE TABLE public.projects ( + id integer NOT NULL, + odkid integer, + author_id bigint NOT NULL, + created timestamp without time zone NOT NULL, + task_creation_mode public.taskcreationmode NOT NULL, + project_name_prefix character varying, + task_type_prefix character varying, + location_str character varying, + outline public.geometry(Polygon,4326), + last_updated timestamp without time zone, + status public.projectstatus NOT NULL, + total_tasks integer, + odk_central_src character varying, + xform_title character varying, + private boolean, + mapper_level public.mappinglevel NOT NULL, + priority public.projectpriority, + featured boolean, + mapping_permission public.mappingpermission, + validation_permission public.validationpermission, + organisation_id integer, + due_date timestamp without time zone, + changeset_comment character varying, + osmcha_filter_id character varying, + imagery character varying, + osm_preset character varying, + odk_preset character varying, + josm_preset character varying, + id_presets character varying[], + extra_id_params character varying, + license_id integer, + centroid public.geometry(Point,4326), + odk_central_url character varying, + odk_central_user character varying, + odk_central_password character varying, + extract_completed_count integer, + form_xls bytea, + form_config_file bytea, + data_extract_type character varying, + task_split_type character varying, + hashtags character varying[] +); +ALTER TABLE public.projects OWNER TO fmtm; +CREATE SEQUENCE public.projects_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; +ALTER TABLE public.projects_id_seq OWNER TO fmtm; +ALTER SEQUENCE public.projects_id_seq OWNED BY public.projects.id; + + +CREATE TABLE public.qr_code ( + id integer NOT NULL, + filename character varying, + image bytea +); +ALTER TABLE public.qr_code OWNER TO fmtm; +CREATE SEQUENCE public.qr_code_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; +ALTER TABLE public.qr_code_id_seq OWNER TO fmtm; +ALTER SEQUENCE public.qr_code_id_seq OWNED BY public.qr_code.id; + + +CREATE TABLE public.splitpolygons ( + polyid bigint NOT NULL, + geom public.geometry(Polygon,4326), + geog public.geography(Geometry,4326), + numfeatures bigint, + area double precision +); +ALTER TABLE public.splitpolygons OWNER TO fmtm; + + +CREATE TABLE public.task_history ( + id integer NOT NULL, + project_id integer, + task_id integer NOT NULL, + action public.taskaction NOT NULL, + action_text character varying, + action_date timestamp without time zone NOT NULL, + user_id bigint NOT NULL +); +ALTER TABLE public.task_history OWNER TO fmtm; +CREATE SEQUENCE public.task_history_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; +ALTER TABLE public.task_history_id_seq OWNER TO fmtm; +ALTER SEQUENCE public.task_history_id_seq OWNED BY public.task_history.id; + + +CREATE TABLE public.task_invalidation_history ( + id integer NOT NULL, + project_id integer NOT NULL, + task_id integer NOT NULL, + is_closed boolean, + mapper_id bigint, + mapped_date timestamp without time zone, + invalidator_id bigint, + invalidated_date timestamp without time zone, + invalidation_history_id integer, + validator_id bigint, + validated_date timestamp without time zone, + updated_date timestamp without time zone +); +ALTER TABLE public.task_invalidation_history OWNER TO fmtm; +CREATE SEQUENCE public.task_invalidation_history_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; +ALTER TABLE public.task_invalidation_history_id_seq OWNER TO fmtm; +ALTER SEQUENCE public.task_invalidation_history_id_seq OWNED BY public.task_invalidation_history.id; + + +CREATE TABLE public.task_mapping_issues ( + id integer NOT NULL, + task_history_id integer NOT NULL, + issue character varying NOT NULL, + mapping_issue_category_id integer NOT NULL, + count integer NOT NULL +); +ALTER TABLE public.task_mapping_issues OWNER TO fmtm; +CREATE SEQUENCE public.task_mapping_issues_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; +ALTER TABLE public.task_mapping_issues_id_seq OWNER TO fmtm; +ALTER SEQUENCE public.task_mapping_issues_id_seq OWNED BY public.task_mapping_issues.id; + + +CREATE TABLE public.taskpolygons ( + geom public.geometry, + clusteruid text +); +ALTER TABLE public.taskpolygons OWNER TO fmtm; + + +CREATE TABLE public.tasks ( + id integer NOT NULL, + project_id integer NOT NULL, + project_task_index integer, + project_task_name character varying, + outline public.geometry(Polygon,4326), + geometry_geojson character varying, + initial_feature_count integer, + task_status public.taskstatus, + locked_by bigint, + mapped_by bigint, + validated_by bigint, + qr_code_id integer +); +ALTER TABLE public.tasks OWNER TO fmtm; +CREATE SEQUENCE public.tasks_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; +ALTER TABLE public.tasks_id_seq OWNER TO fmtm; +ALTER SEQUENCE public.tasks_id_seq OWNED BY public.tasks.id; + + +CREATE TABLE public.teams ( + id integer NOT NULL, + organisation_id integer NOT NULL, + name character varying(512) NOT NULL, + logo character varying, + description character varying, + invite_only boolean NOT NULL, + visibility public.teamvisibility NOT NULL +); +ALTER TABLE public.teams OWNER TO fmtm; +CREATE SEQUENCE public.teams_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; +ALTER TABLE public.teams_id_seq OWNER TO fmtm; +ALTER SEQUENCE public.teams_id_seq OWNED BY public.teams.id; + + +CREATE TABLE public.user_licenses ( + "user" bigint, + license integer +); +ALTER TABLE public.user_licenses OWNER TO fmtm; + + +CREATE TABLE public.user_roles ( + user_id bigint NOT NULL, + organization_id integer, + project_id integer, + role public.userrole NOT NULL +); +ALTER TABLE public.user_roles OWNER TO fmtm; + + +CREATE TABLE public.users ( + id bigint NOT NULL, + username character varying, + role public.userrole NOT NULL, + name character varying, + city character varying, + country character varying, + email_address character varying, + is_email_verified boolean, + is_expert boolean, + mapping_level public.mappinglevel NOT NULL, + tasks_mapped integer NOT NULL, + tasks_validated integer NOT NULL, + tasks_invalidated integer NOT NULL, + projects_mapped integer[], + date_registered timestamp without time zone, + last_validation_date timestamp without time zone, + password character varying +); +ALTER TABLE public.users OWNER TO fmtm; +CREATE SEQUENCE public.users_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; +ALTER TABLE public.users_id_seq OWNER TO fmtm; +ALTER SEQUENCE public.users_id_seq OWNED BY public.users.id; + + +CREATE TABLE public.voronois ( + clusteruid text, + geom public.geometry +); +ALTER TABLE public.voronois OWNER TO fmtm; + + +CREATE TABLE public.ways_line ( + id integer NOT NULL, + project_id character varying, + geom public.geometry(Geometry,4326), + tags jsonb +); +ALTER TABLE public.ways_line OWNER TO fmtm; +CREATE SEQUENCE public.ways_line_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; +ALTER TABLE public.ways_line_id_seq OWNER TO fmtm; +ALTER SEQUENCE public.ways_line_id_seq OWNED BY public.ways_line.id; + + +CREATE TABLE public.ways_poly ( + id integer NOT NULL, + project_id character varying, + osm_id character varying, + geom public.geometry(Geometry,4326), + tags jsonb +); +ALTER TABLE public.ways_poly OWNER TO fmtm; +CREATE SEQUENCE public.ways_poly_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; +ALTER TABLE public.ways_poly_id_seq OWNER TO fmtm; +ALTER SEQUENCE public.ways_poly_id_seq OWNED BY public.ways_poly.id; + + +CREATE TABLE public.xlsforms ( + id integer NOT NULL, + title character varying, + category character varying, + description character varying, + xml character varying, + xls bytea +); +ALTER TABLE public.xlsforms OWNER TO fmtm; +CREATE SEQUENCE public.xlsforms_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; +ALTER TABLE public.xlsforms_id_seq OWNER TO fmtm; +ALTER SEQUENCE public.xlsforms_id_seq OWNED BY public.xlsforms.id; + + +-- nextval for primary keys (autoincrement) + +ALTER TABLE ONLY public.features ALTER COLUMN id SET DEFAULT nextval('public.features_id_seq'::regclass); +ALTER TABLE ONLY public.licenses ALTER COLUMN id SET DEFAULT nextval('public.licenses_id_seq'::regclass); +ALTER TABLE ONLY public.mapping_issue_categories ALTER COLUMN id SET DEFAULT nextval('public.mapping_issue_categories_id_seq'::regclass); +ALTER TABLE ONLY public.mbtiles_path ALTER COLUMN id SET DEFAULT nextval('public.mbtiles_path_id_seq'::regclass); +ALTER TABLE ONLY public.organisations ALTER COLUMN id SET DEFAULT nextval('public.organisations_id_seq'::regclass); +ALTER TABLE ONLY public.project_aoi ALTER COLUMN id SET DEFAULT nextval('public.project_aoi_id_seq'::regclass); +ALTER TABLE ONLY public.project_chat ALTER COLUMN id SET DEFAULT nextval('public.project_chat_id_seq'::regclass); +ALTER TABLE ONLY public.projects ALTER COLUMN id SET DEFAULT nextval('public.projects_id_seq'::regclass); +ALTER TABLE ONLY public.qr_code ALTER COLUMN id SET DEFAULT nextval('public.qr_code_id_seq'::regclass); +ALTER TABLE ONLY public.task_history ALTER COLUMN id SET DEFAULT nextval('public.task_history_id_seq'::regclass); +ALTER TABLE ONLY public.task_invalidation_history ALTER COLUMN id SET DEFAULT nextval('public.task_invalidation_history_id_seq'::regclass); +ALTER TABLE ONLY public.task_mapping_issues ALTER COLUMN id SET DEFAULT nextval('public.task_mapping_issues_id_seq'::regclass); +ALTER TABLE ONLY public.tasks ALTER COLUMN id SET DEFAULT nextval('public.tasks_id_seq'::regclass); +ALTER TABLE ONLY public.teams ALTER COLUMN id SET DEFAULT nextval('public.teams_id_seq'::regclass); +ALTER TABLE ONLY public.users ALTER COLUMN id SET DEFAULT nextval('public.users_id_seq'::regclass); +ALTER TABLE ONLY public.ways_line ALTER COLUMN id SET DEFAULT nextval('public.ways_line_id_seq'::regclass); +ALTER TABLE ONLY public.ways_poly ALTER COLUMN id SET DEFAULT nextval('public.ways_poly_id_seq'::regclass); +ALTER TABLE ONLY public.xlsforms ALTER COLUMN id SET DEFAULT nextval('public.xlsforms_id_seq'::regclass); + + +-- Constraints for primary keys + +ALTER TABLE public."_migrations" + ADD CONSTRAINT "_migrations_pkey" PRIMARY KEY (script_name); + +ALTER TABLE ONLY public.background_tasks + ADD CONSTRAINT background_tasks_pkey PRIMARY KEY (id); + +ALTER TABLE ONLY public.features + ADD CONSTRAINT features_pkey PRIMARY KEY (id); + +ALTER TABLE ONLY public.licenses + ADD CONSTRAINT licenses_name_key UNIQUE (name); + +ALTER TABLE ONLY public.licenses + ADD CONSTRAINT licenses_pkey PRIMARY KEY (id); + +ALTER TABLE ONLY public.lowfeaturecountpolygons + ADD CONSTRAINT lowfeaturecountpolygons_pkey PRIMARY KEY (polyid); + +ALTER TABLE ONLY public.mapping_issue_categories + ADD CONSTRAINT mapping_issue_categories_name_key UNIQUE (name); + +ALTER TABLE ONLY public.mapping_issue_categories + ADD CONSTRAINT mapping_issue_categories_pkey PRIMARY KEY (id); + +ALTER TABLE ONLY public.mbtiles_path + ADD CONSTRAINT mbtiles_path_pkey PRIMARY KEY (id); + +ALTER TABLE ONLY public.organisation_managers + ADD CONSTRAINT organisation_user_key UNIQUE (organisation_id, user_id); + +ALTER TABLE ONLY public.organisations + ADD CONSTRAINT organisations_name_key UNIQUE (name); + +ALTER TABLE ONLY public.organisations + ADD CONSTRAINT organisations_pkey PRIMARY KEY (id); + +ALTER TABLE ONLY public.organisations + ADD CONSTRAINT organisations_slug_key UNIQUE (slug); + +ALTER TABLE ONLY public.project_aoi + ADD CONSTRAINT project_aoi_pkey PRIMARY KEY (id); + +ALTER TABLE ONLY public.project_chat + ADD CONSTRAINT project_chat_pkey PRIMARY KEY (id); + +ALTER TABLE ONLY public.project_info + ADD CONSTRAINT project_info_pkey PRIMARY KEY (project_id); + +ALTER TABLE ONLY public.project_teams + ADD CONSTRAINT project_teams_pkey PRIMARY KEY (team_id, project_id); + +ALTER TABLE ONLY public.projects + ADD CONSTRAINT projects_pkey PRIMARY KEY (id); + +ALTER TABLE ONLY public.qr_code + ADD CONSTRAINT qr_code_pkey PRIMARY KEY (id); + +ALTER TABLE ONLY public.splitpolygons + ADD CONSTRAINT splitpolygons_pkey PRIMARY KEY (polyid); + +ALTER TABLE ONLY public.task_history + ADD CONSTRAINT task_history_pkey PRIMARY KEY (id); + +ALTER TABLE ONLY public.task_invalidation_history + ADD CONSTRAINT task_invalidation_history_pkey PRIMARY KEY (id); + +ALTER TABLE ONLY public.task_mapping_issues + ADD CONSTRAINT task_mapping_issues_pkey PRIMARY KEY (id); + +ALTER TABLE ONLY public.tasks + ADD CONSTRAINT tasks_pkey PRIMARY KEY (id, project_id); + +ALTER TABLE ONLY public.teams + ADD CONSTRAINT teams_pkey PRIMARY KEY (id); + +ALTER TABLE ONLY public.user_roles + ADD CONSTRAINT user_roles_pkey PRIMARY KEY (user_id); + +ALTER TABLE ONLY public.users + ADD CONSTRAINT users_pkey PRIMARY KEY (id); + +ALTER TABLE ONLY public.users + ADD CONSTRAINT users_username_key UNIQUE (username); + +ALTER TABLE ONLY public.ways_line + ADD CONSTRAINT ways_line_pkey PRIMARY KEY (id); + +ALTER TABLE ONLY public.ways_poly + ADD CONSTRAINT ways_poly_pkey PRIMARY KEY (id); + +ALTER TABLE ONLY public.xlsforms + ADD CONSTRAINT xlsforms_pkey PRIMARY KEY (id); + +ALTER TABLE ONLY public.xlsforms + ADD CONSTRAINT xlsforms_title_key UNIQUE (title); + + +-- Indexing + +CREATE INDEX buildings_idx ON public.buildings USING gist (geom); +CREATE INDEX clusteredbuildings_idx ON public.clusteredbuildings USING gist (geom); +CREATE INDEX dumpedpoints_idx ON public.dumpedpoints USING gist (geom); +CREATE INDEX idx_features_composite ON public.features USING btree (task_id, project_id); +CREATE INDEX idx_features_geometry ON public.features USING gist (geometry); +CREATE INDEX idx_geometry ON public.projects USING gist (outline); +CREATE INDEX idx_lowfeaturecountpolygons_geog ON public.lowfeaturecountpolygons USING gist (geog); +CREATE INDEX idx_project_aoi_geom ON public.project_aoi USING gist (geom); +CREATE INDEX idx_projects_centroid ON public.projects USING gist (centroid); +CREATE INDEX idx_projects_outline ON public.projects USING gist (outline); +CREATE INDEX idx_splitpolygons_geog ON public.splitpolygons USING gist (geog); +CREATE INDEX idx_task_history_composite ON public.task_history USING btree (task_id, project_id); +CREATE INDEX idx_task_history_project_id_user_id ON public.task_history USING btree (user_id, project_id); +CREATE INDEX idx_task_validation_history_composite ON public.task_invalidation_history USING btree (task_id, project_id); +CREATE INDEX idx_task_validation_mapper_status_composite ON public.task_invalidation_history USING btree (mapper_id, is_closed); +CREATE INDEX idx_task_validation_validator_status_composite ON public.task_invalidation_history USING btree (invalidator_id, is_closed); +CREATE INDEX idx_tasks_outline ON public.tasks USING gist (outline); +CREATE INDEX idx_ways_line_geom ON public.ways_line USING gist (geom); +CREATE INDEX idx_ways_poly_geom ON public.ways_poly USING gist (geom); +CREATE INDEX ix_project_chat_project_id ON public.project_chat USING btree (project_id); +CREATE INDEX ix_projects_mapper_level ON public.projects USING btree (mapper_level); +CREATE INDEX ix_projects_organisation_id ON public.projects USING btree (organisation_id); +CREATE INDEX ix_task_history_project_id ON public.task_history USING btree (project_id); +CREATE INDEX ix_task_history_user_id ON public.task_history USING btree (user_id); +CREATE INDEX ix_task_mapping_issues_task_history_id ON public.task_mapping_issues USING btree (task_history_id); +CREATE INDEX ix_tasks_locked_by ON public.tasks USING btree (locked_by); +CREATE INDEX ix_tasks_mapped_by ON public.tasks USING btree (mapped_by); +CREATE INDEX ix_tasks_project_id ON public.tasks USING btree (project_id); +CREATE INDEX ix_tasks_qr_code_id ON public.tasks USING btree (qr_code_id); +CREATE INDEX ix_tasks_validated_by ON public.tasks USING btree (validated_by); +CREATE INDEX ix_users_id ON public.users USING btree (id); +CREATE INDEX lowfeaturecountpolygons_idx ON public.lowfeaturecountpolygons USING gist (geom); +CREATE INDEX splitpolygons_idx ON public.splitpolygons USING gist (geom); +CREATE INDEX taskpolygons_idx ON public.taskpolygons USING gist (geom); +CREATE INDEX textsearch_idx ON public.project_info USING btree (text_searchable); +CREATE INDEX voronois_idx ON public.voronois USING gist (geom); + + +-- Foreign keys + +ALTER TABLE ONLY public.features + ADD CONSTRAINT features_project_id_fkey FOREIGN KEY (project_id) REFERENCES public.projects(id); + +ALTER TABLE ONLY public.task_invalidation_history + ADD CONSTRAINT fk_invalidation_history FOREIGN KEY (invalidation_history_id) REFERENCES public.task_history(id); + +ALTER TABLE ONLY public.task_invalidation_history + ADD CONSTRAINT fk_invalidators FOREIGN KEY (invalidator_id) REFERENCES public.users(id); + +ALTER TABLE ONLY public.task_mapping_issues + ADD CONSTRAINT fk_issue_category FOREIGN KEY (mapping_issue_category_id) REFERENCES public.mapping_issue_categories(id); + +ALTER TABLE ONLY public.projects + ADD CONSTRAINT fk_licenses FOREIGN KEY (license_id) REFERENCES public.licenses(id); + +ALTER TABLE ONLY public.task_invalidation_history + ADD CONSTRAINT fk_mappers FOREIGN KEY (mapper_id) REFERENCES public.users(id); + +ALTER TABLE ONLY public.teams + ADD CONSTRAINT fk_organisations FOREIGN KEY (organisation_id) REFERENCES public.organisations(id); + +ALTER TABLE ONLY public.projects + ADD CONSTRAINT fk_organisations FOREIGN KEY (organisation_id) REFERENCES public.organisations(id); + +ALTER TABLE ONLY public.task_history + ADD CONSTRAINT fk_tasks FOREIGN KEY (task_id, project_id) REFERENCES public.tasks(id, project_id); + +ALTER TABLE ONLY public.features + ADD CONSTRAINT fk_tasks FOREIGN KEY (task_id, project_id) REFERENCES public.tasks(id, project_id); + +ALTER TABLE ONLY public.task_invalidation_history + ADD CONSTRAINT fk_tasks FOREIGN KEY (task_id, project_id) REFERENCES public.tasks(id, project_id); + +ALTER TABLE ONLY public.projects + ADD CONSTRAINT fk_users FOREIGN KEY (author_id) REFERENCES public.users(id); + +ALTER TABLE ONLY public.task_history + ADD CONSTRAINT fk_users FOREIGN KEY (user_id) REFERENCES public.users(id); + +ALTER TABLE ONLY public.tasks + ADD CONSTRAINT fk_users_locked FOREIGN KEY (locked_by) REFERENCES public.users(id); + +ALTER TABLE ONLY public.tasks + ADD CONSTRAINT fk_users_mapper FOREIGN KEY (mapped_by) REFERENCES public.users(id); + +ALTER TABLE ONLY public.tasks + ADD CONSTRAINT fk_users_validator FOREIGN KEY (validated_by) REFERENCES public.users(id); + +ALTER TABLE ONLY public.task_invalidation_history + ADD CONSTRAINT fk_validators FOREIGN KEY (validator_id) REFERENCES public.users(id); + +ALTER TABLE ONLY public.projects + ADD CONSTRAINT fk_xform FOREIGN KEY (xform_title) REFERENCES public.xlsforms(title); + +ALTER TABLE ONLY public.features + ADD CONSTRAINT fk_xform FOREIGN KEY (category_title) REFERENCES public.xlsforms(title); + +ALTER TABLE ONLY public.organisation_managers + ADD CONSTRAINT organisation_managers_organisation_id_fkey FOREIGN KEY (organisation_id) REFERENCES public.organisations(id); + +ALTER TABLE ONLY public.organisation_managers + ADD CONSTRAINT organisation_managers_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.users(id); + +ALTER TABLE ONLY public.project_allowed_users + ADD CONSTRAINT project_allowed_users_project_id_fkey FOREIGN KEY (project_id) REFERENCES public.projects(id); + +ALTER TABLE ONLY public.project_allowed_users + ADD CONSTRAINT project_allowed_users_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.users(id); + +ALTER TABLE ONLY public.project_chat + ADD CONSTRAINT project_chat_project_id_fkey FOREIGN KEY (project_id) REFERENCES public.projects(id); + +ALTER TABLE ONLY public.project_chat + ADD CONSTRAINT project_chat_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.users(id); + +ALTER TABLE ONLY public.project_info + ADD CONSTRAINT project_info_project_id_fkey FOREIGN KEY (project_id) REFERENCES public.projects(id); + +ALTER TABLE ONLY public.project_teams + ADD CONSTRAINT project_teams_project_id_fkey FOREIGN KEY (project_id) REFERENCES public.projects(id); + +ALTER TABLE ONLY public.project_teams + ADD CONSTRAINT project_teams_team_id_fkey FOREIGN KEY (team_id) REFERENCES public.teams(id); + +ALTER TABLE ONLY public.task_history + ADD CONSTRAINT task_history_project_id_fkey FOREIGN KEY (project_id) REFERENCES public.projects(id); + +ALTER TABLE ONLY public.task_invalidation_history + ADD CONSTRAINT task_invalidation_history_project_id_fkey FOREIGN KEY (project_id) REFERENCES public.projects(id); + +ALTER TABLE ONLY public.task_mapping_issues + ADD CONSTRAINT task_mapping_issues_task_history_id_fkey FOREIGN KEY (task_history_id) REFERENCES public.task_history(id); + +ALTER TABLE ONLY public.tasks + ADD CONSTRAINT tasks_project_id_fkey FOREIGN KEY (project_id) REFERENCES public.projects(id); + +ALTER TABLE ONLY public.tasks + ADD CONSTRAINT tasks_qr_code_id_fkey FOREIGN KEY (qr_code_id) REFERENCES public.qr_code(id); + +ALTER TABLE ONLY public.user_licenses + ADD CONSTRAINT user_licenses_license_fkey FOREIGN KEY (license) REFERENCES public.licenses(id); + +ALTER TABLE ONLY public.user_licenses + ADD CONSTRAINT user_licenses_user_fkey FOREIGN KEY ("user") REFERENCES public.users(id); + +ALTER TABLE ONLY public.user_roles + ADD CONSTRAINT user_roles_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES public.organisations(id); + +ALTER TABLE ONLY public.user_roles + ADD CONSTRAINT user_roles_project_id_fkey FOREIGN KEY (project_id) REFERENCES public.projects(id); + +ALTER TABLE ONLY public.user_roles + ADD CONSTRAINT user_roles_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.users(id); + + +-- Finalise + +REVOKE USAGE ON SCHEMA public FROM PUBLIC; +GRANT ALL ON SCHEMA public TO PUBLIC; diff --git a/src/backend/migrations/script.py.mako b/src/backend/migrations/script.py.mako deleted file mode 100644 index 37d0cac313..0000000000 --- a/src/backend/migrations/script.py.mako +++ /dev/null @@ -1,24 +0,0 @@ -"""${message} - -Revision ID: ${up_revision} -Revises: ${down_revision | comma,n} -Create Date: ${create_date} - -""" -from alembic import op -import sqlalchemy as sa -${imports if imports else ""} - -# revision identifiers, used by Alembic. -revision = ${repr(up_revision)} -down_revision = ${repr(down_revision)} -branch_labels = ${repr(branch_labels)} -depends_on = ${repr(depends_on)} - - -def upgrade() -> None: - ${upgrades if upgrades else "pass"} - - -def downgrade() -> None: - ${downgrades if downgrades else "pass"} \ No newline at end of file diff --git a/src/backend/migrations/versions/ec28a415c8d8_create_inital_tables.py b/src/backend/migrations/versions/ec28a415c8d8_create_inital_tables.py deleted file mode 100644 index 8aa8382f5a..0000000000 --- a/src/backend/migrations/versions/ec28a415c8d8_create_inital_tables.py +++ /dev/null @@ -1,2153 +0,0 @@ -"""create inital tables. - -Revision ID: ec28a415c8d8 -Revises: -Create Date: 2023-09-26 09:04:00.676103 - -""" -import imp -import os - -import geoalchemy2 -import sqlalchemy as sa -from alembic import op -from sqlalchemy.dialects import postgresql - -alembic_helpers = imp.load_source( - "alembic_helpers", - (os.getcwd() + "/" + op.get_context().script.dir + "/alembic_helpers.py"), -) - -# revision identifiers, used by Alembic. -revision = "ec28a415c8d8" -down_revision = None -branch_labels = None -depends_on = None - - -def upgrade() -> None: - # ### commands auto generated by Alembic - please adjust! ### - if alembic_helpers.table_does_not_exist("loader_platform"): - op.create_table( - "loader_platform", - sa.Column("os", sa.VARCHAR(length=50), autoincrement=False, nullable=False), - sa.Column("declare_sect", sa.TEXT(), autoincrement=False, nullable=True), - sa.Column("pgbin", sa.TEXT(), autoincrement=False, nullable=True), - sa.Column("wget", sa.TEXT(), autoincrement=False, nullable=True), - sa.Column("unzip_command", sa.TEXT(), autoincrement=False, nullable=True), - sa.Column("psql", sa.TEXT(), autoincrement=False, nullable=True), - sa.Column("path_sep", sa.TEXT(), autoincrement=False, nullable=True), - sa.Column("loader", sa.TEXT(), autoincrement=False, nullable=True), - sa.Column( - "environ_set_command", sa.TEXT(), autoincrement=False, nullable=True - ), - sa.Column( - "county_process_command", sa.TEXT(), autoincrement=False, nullable=True - ), - sa.PrimaryKeyConstraint("os", name="loader_platform_pkey"), - ) - - if alembic_helpers.table_does_not_exist("dumpedpoints"): - op.create_table( - "dumpedpoints", - sa.Column("osm_id", sa.VARCHAR(), autoincrement=False, nullable=True), - sa.Column("polyid", sa.BIGINT(), autoincrement=False, nullable=True), - sa.Column("cid", sa.INTEGER(), autoincrement=False, nullable=True), - sa.Column("clusteruid", sa.TEXT(), autoincrement=False, nullable=True), - sa.Column( - "geom", - geoalchemy2.types.Geometry( - geometry_type="POINT", - srid=4326, - from_text="ST_GeomFromEWKT", - name="geometry", - _spatial_index_reflected=True, - ), - autoincrement=False, - nullable=True, - ), - ) - op.create_index( - "dumpedpoints_idx", - "dumpedpoints", - ["geom"], - unique=False, - postgresql_using="gist", - ) - - if alembic_helpers.table_does_not_exist("pagc_lex"): - op.create_table( - "pagc_lex", - sa.Column("id", sa.INTEGER(), autoincrement=True, nullable=False), - sa.Column("seq", sa.INTEGER(), autoincrement=False, nullable=True), - sa.Column("word", sa.TEXT(), autoincrement=False, nullable=True), - sa.Column("stdword", sa.TEXT(), autoincrement=False, nullable=True), - sa.Column("token", sa.INTEGER(), autoincrement=False, nullable=True), - sa.Column( - "is_custom", - sa.BOOLEAN(), - server_default=sa.text("true"), - autoincrement=False, - nullable=False, - ), - sa.PrimaryKeyConstraint("id", name="pagc_lex_pkey"), - ) - - if alembic_helpers.table_does_not_exist("zip_lookup_all"): - op.create_table( - "zip_lookup_all", - sa.Column("zip", sa.INTEGER(), autoincrement=False, nullable=True), - sa.Column("st_code", sa.INTEGER(), autoincrement=False, nullable=True), - sa.Column( - "state", sa.VARCHAR(length=2), autoincrement=False, nullable=True - ), - sa.Column("co_code", sa.INTEGER(), autoincrement=False, nullable=True), - sa.Column( - "county", sa.VARCHAR(length=90), autoincrement=False, nullable=True - ), - sa.Column("cs_code", sa.INTEGER(), autoincrement=False, nullable=True), - sa.Column( - "cousub", sa.VARCHAR(length=90), autoincrement=False, nullable=True - ), - sa.Column("pl_code", sa.INTEGER(), autoincrement=False, nullable=True), - sa.Column( - "place", sa.VARCHAR(length=90), autoincrement=False, nullable=True - ), - sa.Column("cnt", sa.INTEGER(), autoincrement=False, nullable=True), - ) - - if alembic_helpers.table_does_not_exist("pagc_rules"): - op.create_table( - "pagc_rules", - sa.Column("id", sa.INTEGER(), autoincrement=True, nullable=False), - sa.Column("rule", sa.TEXT(), autoincrement=False, nullable=True), - sa.Column( - "is_custom", - sa.BOOLEAN(), - server_default=sa.text("true"), - autoincrement=False, - nullable=True, - ), - sa.PrimaryKeyConstraint("id", name="pagc_rules_pkey"), - ) - - if alembic_helpers.table_does_not_exist("addrfeat"): - op.create_table( - "addrfeat", - sa.Column("gid", sa.INTEGER(), autoincrement=True, nullable=False), - sa.Column("tlid", sa.BIGINT(), autoincrement=False, nullable=True), - sa.Column( - "statefp", sa.VARCHAR(length=2), autoincrement=False, nullable=False - ), - sa.Column( - "aridl", sa.VARCHAR(length=22), autoincrement=False, nullable=True - ), - sa.Column( - "aridr", sa.VARCHAR(length=22), autoincrement=False, nullable=True - ), - sa.Column( - "linearid", sa.VARCHAR(length=22), autoincrement=False, nullable=True - ), - sa.Column( - "fullname", sa.VARCHAR(length=100), autoincrement=False, nullable=True - ), - sa.Column( - "lfromhn", sa.VARCHAR(length=12), autoincrement=False, nullable=True - ), - sa.Column( - "ltohn", sa.VARCHAR(length=12), autoincrement=False, nullable=True - ), - sa.Column( - "rfromhn", sa.VARCHAR(length=12), autoincrement=False, nullable=True - ), - sa.Column( - "rtohn", sa.VARCHAR(length=12), autoincrement=False, nullable=True - ), - sa.Column("zipl", sa.VARCHAR(length=5), autoincrement=False, nullable=True), - sa.Column("zipr", sa.VARCHAR(length=5), autoincrement=False, nullable=True), - sa.Column( - "edge_mtfcc", sa.VARCHAR(length=5), autoincrement=False, nullable=True - ), - sa.Column( - "parityl", sa.VARCHAR(length=1), autoincrement=False, nullable=True - ), - sa.Column( - "parityr", sa.VARCHAR(length=1), autoincrement=False, nullable=True - ), - sa.Column( - "plus4l", sa.VARCHAR(length=4), autoincrement=False, nullable=True - ), - sa.Column( - "plus4r", sa.VARCHAR(length=4), autoincrement=False, nullable=True - ), - sa.Column( - "lfromtyp", sa.VARCHAR(length=1), autoincrement=False, nullable=True - ), - sa.Column( - "ltotyp", sa.VARCHAR(length=1), autoincrement=False, nullable=True - ), - sa.Column( - "rfromtyp", sa.VARCHAR(length=1), autoincrement=False, nullable=True - ), - sa.Column( - "rtotyp", sa.VARCHAR(length=1), autoincrement=False, nullable=True - ), - sa.Column( - "offsetl", sa.VARCHAR(length=1), autoincrement=False, nullable=True - ), - sa.Column( - "offsetr", sa.VARCHAR(length=1), autoincrement=False, nullable=True - ), - sa.Column( - "the_geom", - geoalchemy2.types.Geometry( - from_text="ST_GeomFromEWKT", - name="geometry", - _spatial_index_reflected=True, - ), - autoincrement=False, - nullable=True, - ), - sa.CheckConstraint( - "geometrytype(the_geom) = 'LINESTRING'::text OR the_geom IS NULL", - name="enforce_geotype_the_geom", - ), - sa.CheckConstraint("st_ndims(the_geom) = 2", name="enforce_dims_the_geom"), - sa.CheckConstraint( - "st_srid(the_geom) = 4269", name="enforce_srid_the_geom" - ), - sa.PrimaryKeyConstraint("gid", name="addrfeat_pkey"), - ) - op.create_index("idx_addrfeat_zipr", "addrfeat", ["zipr"], unique=False) - op.create_index("idx_addrfeat_zipl", "addrfeat", ["zipl"], unique=False) - op.create_index("idx_addrfeat_tlid", "addrfeat", ["tlid"], unique=False) - op.create_index( - "idx_addrfeat_geom_gist", - "addrfeat", - ["the_geom"], - unique=False, - postgresql_using="gist", - ) - - if alembic_helpers.table_does_not_exist("topology"): - op.create_table( - "topology", - sa.Column( - "id", - sa.INTEGER(), - server_default=sa.text("nextval('topology_id_seq'::regclass)"), - autoincrement=True, - nullable=False, - ), - sa.Column("name", sa.VARCHAR(), autoincrement=False, nullable=False), - sa.Column("srid", sa.INTEGER(), autoincrement=False, nullable=False), - sa.Column( - "precision", - sa.DOUBLE_PRECISION(precision=53), - autoincrement=False, - nullable=False, - ), - sa.Column( - "hasz", - sa.BOOLEAN(), - server_default=sa.text("false"), - autoincrement=False, - nullable=False, - ), - sa.PrimaryKeyConstraint("id", name="topology_pkey"), - sa.UniqueConstraint("name", name="topology_name_key"), - postgresql_ignore_search_path=False, - ) - - if alembic_helpers.table_does_not_exist("featnames"): - op.create_table( - "featnames", - sa.Column("gid", sa.INTEGER(), autoincrement=True, nullable=False), - sa.Column("tlid", sa.BIGINT(), autoincrement=False, nullable=True), - sa.Column( - "fullname", sa.VARCHAR(length=100), autoincrement=False, nullable=True - ), - sa.Column( - "name", sa.VARCHAR(length=100), autoincrement=False, nullable=True - ), - sa.Column( - "predirabrv", sa.VARCHAR(length=15), autoincrement=False, nullable=True - ), - sa.Column( - "pretypabrv", sa.VARCHAR(length=50), autoincrement=False, nullable=True - ), - sa.Column( - "prequalabr", sa.VARCHAR(length=15), autoincrement=False, nullable=True - ), - sa.Column( - "sufdirabrv", sa.VARCHAR(length=15), autoincrement=False, nullable=True - ), - sa.Column( - "suftypabrv", sa.VARCHAR(length=50), autoincrement=False, nullable=True - ), - sa.Column( - "sufqualabr", sa.VARCHAR(length=15), autoincrement=False, nullable=True - ), - sa.Column( - "predir", sa.VARCHAR(length=2), autoincrement=False, nullable=True - ), - sa.Column( - "pretyp", sa.VARCHAR(length=3), autoincrement=False, nullable=True - ), - sa.Column( - "prequal", sa.VARCHAR(length=2), autoincrement=False, nullable=True - ), - sa.Column( - "sufdir", sa.VARCHAR(length=2), autoincrement=False, nullable=True - ), - sa.Column( - "suftyp", sa.VARCHAR(length=3), autoincrement=False, nullable=True - ), - sa.Column( - "sufqual", sa.VARCHAR(length=2), autoincrement=False, nullable=True - ), - sa.Column( - "linearid", sa.VARCHAR(length=22), autoincrement=False, nullable=True - ), - sa.Column( - "mtfcc", sa.VARCHAR(length=5), autoincrement=False, nullable=True - ), - sa.Column( - "paflag", sa.VARCHAR(length=1), autoincrement=False, nullable=True - ), - sa.Column( - "statefp", sa.VARCHAR(length=2), autoincrement=False, nullable=True - ), - sa.PrimaryKeyConstraint("gid", name="featnames_pkey"), - ) - op.create_index( - "idx_tiger_featnames_tlid_statefp", - "featnames", - ["tlid", "statefp"], - unique=False, - ) - op.create_index( - "idx_tiger_featnames_snd_name", - "featnames", - [sa.text("soundex(name::text)")], - unique=False, - ) - op.create_index( - "idx_tiger_featnames_lname", - "featnames", - [sa.text("lower(name::text)")], - unique=False, - ) - - if alembic_helpers.table_does_not_exist("buildings"): - op.create_table( - "buildings", - sa.Column("id", sa.INTEGER(), autoincrement=False, nullable=True), - sa.Column("project_id", sa.VARCHAR(), autoincrement=False, nullable=True), - sa.Column("osm_id", sa.VARCHAR(), autoincrement=False, nullable=True), - sa.Column( - "geom", - geoalchemy2.types.Geometry( - geometry_type="POLYGON", - srid=4326, - from_text="ST_GeomFromEWKT", - name="geometry", - _spatial_index_reflected=True, - ), - autoincrement=False, - nullable=True, - ), - sa.Column( - "tags", - postgresql.JSONB(astext_type=sa.Text()), - autoincrement=False, - nullable=True, - ), - sa.Column("polyid", sa.BIGINT(), autoincrement=False, nullable=True), - ) - op.create_index( - "buildings_idx", - "buildings", - ["geom"], - unique=False, - postgresql_using="gist", - ) - - if alembic_helpers.table_does_not_exist("zcta5"): - op.create_table( - "zcta5", - sa.Column("gid", sa.INTEGER(), autoincrement=True, nullable=False), - sa.Column( - "statefp", sa.VARCHAR(length=2), autoincrement=False, nullable=False - ), - sa.Column( - "zcta5ce", sa.VARCHAR(length=5), autoincrement=False, nullable=False - ), - sa.Column( - "classfp", sa.VARCHAR(length=2), autoincrement=False, nullable=True - ), - sa.Column( - "mtfcc", sa.VARCHAR(length=5), autoincrement=False, nullable=True - ), - sa.Column( - "funcstat", sa.VARCHAR(length=1), autoincrement=False, nullable=True - ), - sa.Column( - "aland", - sa.DOUBLE_PRECISION(precision=53), - autoincrement=False, - nullable=True, - ), - sa.Column( - "awater", - sa.DOUBLE_PRECISION(precision=53), - autoincrement=False, - nullable=True, - ), - sa.Column( - "intptlat", sa.VARCHAR(length=11), autoincrement=False, nullable=True - ), - sa.Column( - "intptlon", sa.VARCHAR(length=12), autoincrement=False, nullable=True - ), - sa.Column( - "partflg", sa.VARCHAR(length=1), autoincrement=False, nullable=True - ), - sa.Column( - "the_geom", - geoalchemy2.types.Geometry( - spatial_index=False, - from_text="ST_GeomFromEWKT", - name="geometry", - _spatial_index_reflected=True, - ), - autoincrement=False, - nullable=True, - ), - sa.CheckConstraint( - "geometrytype(the_geom) = 'MULTIPOLYGON'::text OR the_geom IS NULL", - name="enforce_geotype_the_geom", - ), - sa.CheckConstraint("st_ndims(the_geom) = 2", name="enforce_dims_the_geom"), - sa.CheckConstraint( - "st_srid(the_geom) = 4269", name="enforce_srid_the_geom" - ), - sa.PrimaryKeyConstraint( - "zcta5ce", "statefp", name="pk_tiger_zcta5_zcta5ce" - ), - sa.UniqueConstraint("gid", name="uidx_tiger_zcta5_gid"), - ) - - if alembic_helpers.table_does_not_exist("secondary_unit_lookup"): - op.create_table( - "secondary_unit_lookup", - sa.Column( - "name", sa.VARCHAR(length=20), autoincrement=False, nullable=False - ), - sa.Column( - "abbrev", sa.VARCHAR(length=5), autoincrement=False, nullable=True - ), - sa.PrimaryKeyConstraint("name", name="secondary_unit_lookup_pkey"), - ) - op.create_index( - "secondary_unit_lookup_abbrev_idx", - "secondary_unit_lookup", - ["abbrev"], - unique=False, - ) - - if alembic_helpers.table_does_not_exist("pagc_gaz"): - op.create_table( - "pagc_gaz", - sa.Column("id", sa.INTEGER(), autoincrement=True, nullable=False), - sa.Column("seq", sa.INTEGER(), autoincrement=False, nullable=True), - sa.Column("word", sa.TEXT(), autoincrement=False, nullable=True), - sa.Column("stdword", sa.TEXT(), autoincrement=False, nullable=True), - sa.Column("token", sa.INTEGER(), autoincrement=False, nullable=True), - sa.Column( - "is_custom", - sa.BOOLEAN(), - server_default=sa.text("true"), - autoincrement=False, - nullable=False, - ), - sa.PrimaryKeyConstraint("id", name="pagc_gaz_pkey"), - ) - - if alembic_helpers.table_does_not_exist("direction_lookup"): - op.create_table( - "direction_lookup", - sa.Column( - "name", sa.VARCHAR(length=20), autoincrement=False, nullable=False - ), - sa.Column( - "abbrev", sa.VARCHAR(length=3), autoincrement=False, nullable=True - ), - sa.PrimaryKeyConstraint("name", name="direction_lookup_pkey"), - ) - op.create_index( - "direction_lookup_abbrev_idx", "direction_lookup", ["abbrev"], unique=False - ) - - if alembic_helpers.table_does_not_exist("state_lookup"): - op.create_table( - "state_lookup", - sa.Column("st_code", sa.INTEGER(), autoincrement=False, nullable=False), - sa.Column( - "name", sa.VARCHAR(length=40), autoincrement=False, nullable=True - ), - sa.Column( - "abbrev", sa.VARCHAR(length=3), autoincrement=False, nullable=True - ), - sa.Column("statefp", sa.CHAR(length=2), autoincrement=False, nullable=True), - sa.PrimaryKeyConstraint("st_code", name="state_lookup_pkey"), - sa.UniqueConstraint("abbrev", name="state_lookup_abbrev_key"), - sa.UniqueConstraint("name", name="state_lookup_name_key"), - sa.UniqueConstraint("statefp", name="state_lookup_statefp_key"), - ) - - if alembic_helpers.table_does_not_exist("tabblock20"): - op.create_table( - "tabblock20", - sa.Column( - "statefp", sa.VARCHAR(length=2), autoincrement=False, nullable=True - ), - sa.Column( - "countyfp", sa.VARCHAR(length=3), autoincrement=False, nullable=True - ), - sa.Column( - "tractce", sa.VARCHAR(length=6), autoincrement=False, nullable=True - ), - sa.Column( - "blockce", sa.VARCHAR(length=4), autoincrement=False, nullable=True - ), - sa.Column( - "geoid", sa.VARCHAR(length=15), autoincrement=False, nullable=False - ), - sa.Column( - "name", sa.VARCHAR(length=10), autoincrement=False, nullable=True - ), - sa.Column( - "mtfcc", sa.VARCHAR(length=5), autoincrement=False, nullable=True - ), - sa.Column("ur", sa.VARCHAR(length=1), autoincrement=False, nullable=True), - sa.Column("uace", sa.VARCHAR(length=5), autoincrement=False, nullable=True), - sa.Column( - "uatype", sa.VARCHAR(length=1), autoincrement=False, nullable=True - ), - sa.Column( - "funcstat", sa.VARCHAR(length=1), autoincrement=False, nullable=True - ), - sa.Column( - "aland", - sa.DOUBLE_PRECISION(precision=53), - autoincrement=False, - nullable=True, - ), - sa.Column( - "awater", - sa.DOUBLE_PRECISION(precision=53), - autoincrement=False, - nullable=True, - ), - sa.Column( - "intptlat", sa.VARCHAR(length=11), autoincrement=False, nullable=True - ), - sa.Column( - "intptlon", sa.VARCHAR(length=12), autoincrement=False, nullable=True - ), - sa.Column( - "the_geom", - geoalchemy2.types.Geometry( - geometry_type="MULTIPOLYGON", - srid=4269, - spatial_index=False, - from_text="ST_GeomFromEWKT", - name="geometry", - _spatial_index_reflected=True, - ), - autoincrement=False, - nullable=True, - ), - sa.Column( - "housing", - sa.DOUBLE_PRECISION(precision=53), - autoincrement=False, - nullable=True, - ), - sa.Column( - "pop", - sa.DOUBLE_PRECISION(precision=53), - autoincrement=False, - nullable=True, - ), - sa.PrimaryKeyConstraint("geoid", name="pk_tabblock20"), - ) - - if alembic_helpers.table_does_not_exist("splitpolygons"): - op.create_table( - "splitpolygons", - sa.Column("polyid", sa.BIGINT(), autoincrement=False, nullable=False), - sa.Column( - "geom", - geoalchemy2.types.Geometry( - geometry_type="POLYGON", - srid=4326, - from_text="ST_GeomFromEWKT", - name="geometry", - _spatial_index_reflected=True, - ), - autoincrement=False, - nullable=True, - ), - sa.Column( - "geog", - geoalchemy2.types.Geography( - from_text="ST_GeogFromText", name="geography" - ), - autoincrement=False, - nullable=True, - ), - sa.Column("numfeatures", sa.BIGINT(), autoincrement=False, nullable=True), - sa.Column( - "area", - sa.DOUBLE_PRECISION(precision=53), - autoincrement=False, - nullable=True, - ), - sa.PrimaryKeyConstraint("polyid", name="splitpolygons_pkey"), - ) - op.create_index( - "splitpolygons_idx", - "splitpolygons", - ["geom"], - unique=False, - postgresql_using="gist", - ) - - if alembic_helpers.table_does_not_exist("cousub"): - op.create_table( - "cousub", - sa.Column("gid", sa.INTEGER(), autoincrement=True, nullable=False), - sa.Column( - "statefp", sa.VARCHAR(length=2), autoincrement=False, nullable=True - ), - sa.Column( - "countyfp", sa.VARCHAR(length=3), autoincrement=False, nullable=True - ), - sa.Column( - "cousubfp", sa.VARCHAR(length=5), autoincrement=False, nullable=True - ), - sa.Column( - "cousubns", sa.VARCHAR(length=8), autoincrement=False, nullable=True - ), - sa.Column( - "cosbidfp", sa.VARCHAR(length=10), autoincrement=False, nullable=False - ), - sa.Column( - "name", sa.VARCHAR(length=100), autoincrement=False, nullable=True - ), - sa.Column( - "namelsad", sa.VARCHAR(length=100), autoincrement=False, nullable=True - ), - sa.Column("lsad", sa.VARCHAR(length=2), autoincrement=False, nullable=True), - sa.Column( - "classfp", sa.VARCHAR(length=2), autoincrement=False, nullable=True - ), - sa.Column( - "mtfcc", sa.VARCHAR(length=5), autoincrement=False, nullable=True - ), - sa.Column( - "cnectafp", sa.VARCHAR(length=3), autoincrement=False, nullable=True - ), - sa.Column( - "nectafp", sa.VARCHAR(length=5), autoincrement=False, nullable=True - ), - sa.Column( - "nctadvfp", sa.VARCHAR(length=5), autoincrement=False, nullable=True - ), - sa.Column( - "funcstat", sa.VARCHAR(length=1), autoincrement=False, nullable=True - ), - sa.Column( - "aland", - sa.NUMERIC(precision=14, scale=0), - autoincrement=False, - nullable=True, - ), - sa.Column( - "awater", - sa.NUMERIC(precision=14, scale=0), - autoincrement=False, - nullable=True, - ), - sa.Column( - "intptlat", sa.VARCHAR(length=11), autoincrement=False, nullable=True - ), - sa.Column( - "intptlon", sa.VARCHAR(length=12), autoincrement=False, nullable=True - ), - sa.Column( - "the_geom", - geoalchemy2.types.Geometry( - from_text="ST_GeomFromEWKT", - name="geometry", - _spatial_index_reflected=True, - ), - autoincrement=False, - nullable=True, - ), - sa.CheckConstraint( - "geometrytype(the_geom) = 'MULTIPOLYGON'::text OR the_geom IS NULL", - name="enforce_geotype_the_geom", - ), - sa.CheckConstraint("st_ndims(the_geom) = 2", name="enforce_dims_the_geom"), - sa.CheckConstraint( - "st_srid(the_geom) = 4269", name="enforce_srid_the_geom" - ), - sa.PrimaryKeyConstraint("cosbidfp", name="cousub_pkey"), - sa.UniqueConstraint("gid", name="uidx_cousub_gid"), - ) - op.create_index( - "tige_cousub_the_geom_gist", - "cousub", - ["the_geom"], - unique=False, - postgresql_using="gist", - ) - - if alembic_helpers.table_does_not_exist("zip_state"): - op.create_table( - "zip_state", - sa.Column("zip", sa.VARCHAR(length=5), autoincrement=False, nullable=False), - sa.Column( - "stusps", sa.VARCHAR(length=2), autoincrement=False, nullable=False - ), - sa.Column( - "statefp", sa.VARCHAR(length=2), autoincrement=False, nullable=True - ), - sa.PrimaryKeyConstraint("zip", "stusps", name="zip_state_pkey"), - ) - - if alembic_helpers.table_does_not_exist("place_lookup"): - op.create_table( - "place_lookup", - sa.Column("st_code", sa.INTEGER(), autoincrement=False, nullable=False), - sa.Column( - "state", sa.VARCHAR(length=2), autoincrement=False, nullable=True - ), - sa.Column("pl_code", sa.INTEGER(), autoincrement=False, nullable=False), - sa.Column( - "name", sa.VARCHAR(length=90), autoincrement=False, nullable=True - ), - sa.PrimaryKeyConstraint("st_code", "pl_code", name="place_lookup_pkey"), - ) - op.create_index( - "place_lookup_state_idx", "place_lookup", ["state"], unique=False - ) - op.create_index( - "place_lookup_name_idx", - "place_lookup", - [sa.text("soundex(name::text)")], - unique=False, - ) - - if alembic_helpers.table_does_not_exist("lowfeaturecountpolygons"): - op.create_table( - "lowfeaturecountpolygons", - sa.Column("polyid", sa.BIGINT(), autoincrement=False, nullable=False), - sa.Column( - "geom", - geoalchemy2.types.Geometry( - geometry_type="POLYGON", - srid=4326, - from_text="ST_GeomFromEWKT", - name="geometry", - _spatial_index_reflected=True, - ), - autoincrement=False, - nullable=True, - ), - sa.Column( - "geog", - geoalchemy2.types.Geography( - from_text="ST_GeogFromText", name="geography" - ), - autoincrement=False, - nullable=True, - ), - sa.Column("numfeatures", sa.BIGINT(), autoincrement=False, nullable=True), - sa.Column( - "area", - sa.DOUBLE_PRECISION(precision=53), - autoincrement=False, - nullable=True, - ), - sa.Column("n_polyid", sa.BIGINT(), autoincrement=False, nullable=True), - sa.Column( - "n_area", - sa.DOUBLE_PRECISION(precision=53), - autoincrement=False, - nullable=True, - ), - sa.Column("n_numfeatures", sa.BIGINT(), autoincrement=False, nullable=True), - sa.Column( - "sharedbound", - sa.DOUBLE_PRECISION(precision=53), - autoincrement=False, - nullable=True, - ), - sa.PrimaryKeyConstraint("polyid", name="lowfeaturecountpolygons_pkey"), - ) - op.create_index( - "lowfeaturecountpolygons_idx", - "lowfeaturecountpolygons", - ["geom"], - unique=False, - postgresql_using="gist", - ) - - if alembic_helpers.table_does_not_exist("place"): - op.create_table( - "place", - sa.Column("gid", sa.INTEGER(), autoincrement=True, nullable=False), - sa.Column( - "statefp", sa.VARCHAR(length=2), autoincrement=False, nullable=True - ), - sa.Column( - "placefp", sa.VARCHAR(length=5), autoincrement=False, nullable=True - ), - sa.Column( - "placens", sa.VARCHAR(length=8), autoincrement=False, nullable=True - ), - sa.Column( - "plcidfp", sa.VARCHAR(length=7), autoincrement=False, nullable=False - ), - sa.Column( - "name", sa.VARCHAR(length=100), autoincrement=False, nullable=True - ), - sa.Column( - "namelsad", sa.VARCHAR(length=100), autoincrement=False, nullable=True - ), - sa.Column("lsad", sa.VARCHAR(length=2), autoincrement=False, nullable=True), - sa.Column( - "classfp", sa.VARCHAR(length=2), autoincrement=False, nullable=True - ), - sa.Column("cpi", sa.VARCHAR(length=1), autoincrement=False, nullable=True), - sa.Column( - "pcicbsa", sa.VARCHAR(length=1), autoincrement=False, nullable=True - ), - sa.Column( - "pcinecta", sa.VARCHAR(length=1), autoincrement=False, nullable=True - ), - sa.Column( - "mtfcc", sa.VARCHAR(length=5), autoincrement=False, nullable=True - ), - sa.Column( - "funcstat", sa.VARCHAR(length=1), autoincrement=False, nullable=True - ), - sa.Column("aland", sa.BIGINT(), autoincrement=False, nullable=True), - sa.Column("awater", sa.BIGINT(), autoincrement=False, nullable=True), - sa.Column( - "intptlat", sa.VARCHAR(length=11), autoincrement=False, nullable=True - ), - sa.Column( - "intptlon", sa.VARCHAR(length=12), autoincrement=False, nullable=True - ), - sa.Column( - "the_geom", - geoalchemy2.types.Geometry( - from_text="ST_GeomFromEWKT", - name="geometry", - _spatial_index_reflected=True, - ), - autoincrement=False, - nullable=True, - ), - sa.CheckConstraint( - "geometrytype(the_geom) = 'MULTIPOLYGON'::text OR the_geom IS NULL", - name="enforce_geotype_the_geom", - ), - sa.CheckConstraint("st_ndims(the_geom) = 2", name="enforce_dims_the_geom"), - sa.CheckConstraint( - "st_srid(the_geom) = 4269", name="enforce_srid_the_geom" - ), - sa.PrimaryKeyConstraint("plcidfp", name="place_pkey"), - sa.UniqueConstraint("gid", name="uidx_tiger_place_gid"), - ) - op.create_index( - "tiger_place_the_geom_gist", - "place", - ["the_geom"], - unique=False, - postgresql_using="gist", - ) - - if alembic_helpers.table_does_not_exist("zip_state_loc"): - op.create_table( - "zip_state_loc", - sa.Column("zip", sa.VARCHAR(length=5), autoincrement=False, nullable=False), - sa.Column( - "stusps", sa.VARCHAR(length=2), autoincrement=False, nullable=False - ), - sa.Column( - "statefp", sa.VARCHAR(length=2), autoincrement=False, nullable=True - ), - sa.Column( - "place", sa.VARCHAR(length=100), autoincrement=False, nullable=False - ), - sa.PrimaryKeyConstraint( - "zip", "stusps", "place", name="zip_state_loc_pkey" - ), - ) - - if alembic_helpers.table_does_not_exist("zip_lookup"): - op.create_table( - "zip_lookup", - sa.Column("zip", sa.INTEGER(), autoincrement=False, nullable=False), - sa.Column("st_code", sa.INTEGER(), autoincrement=False, nullable=True), - sa.Column( - "state", sa.VARCHAR(length=2), autoincrement=False, nullable=True - ), - sa.Column("co_code", sa.INTEGER(), autoincrement=False, nullable=True), - sa.Column( - "county", sa.VARCHAR(length=90), autoincrement=False, nullable=True - ), - sa.Column("cs_code", sa.INTEGER(), autoincrement=False, nullable=True), - sa.Column( - "cousub", sa.VARCHAR(length=90), autoincrement=False, nullable=True - ), - sa.Column("pl_code", sa.INTEGER(), autoincrement=False, nullable=True), - sa.Column( - "place", sa.VARCHAR(length=90), autoincrement=False, nullable=True - ), - sa.Column("cnt", sa.INTEGER(), autoincrement=False, nullable=True), - sa.PrimaryKeyConstraint("zip", name="zip_lookup_pkey"), - ) - - if alembic_helpers.table_does_not_exist("county_lookup"): - op.create_table( - "county_lookup", - sa.Column("st_code", sa.INTEGER(), autoincrement=False, nullable=False), - sa.Column( - "state", sa.VARCHAR(length=2), autoincrement=False, nullable=True - ), - sa.Column("co_code", sa.INTEGER(), autoincrement=False, nullable=False), - sa.Column( - "name", sa.VARCHAR(length=90), autoincrement=False, nullable=True - ), - sa.PrimaryKeyConstraint("st_code", "co_code", name="county_lookup_pkey"), - ) - op.create_index( - "county_lookup_state_idx", "county_lookup", ["state"], unique=False - ) - op.create_index( - "county_lookup_name_idx", - "county_lookup", - [sa.text("soundex(name::text)")], - unique=False, - ) - - if alembic_helpers.table_does_not_exist("geocode_settings"): - op.create_table( - "geocode_settings", - sa.Column("name", sa.TEXT(), autoincrement=False, nullable=False), - sa.Column("setting", sa.TEXT(), autoincrement=False, nullable=True), - sa.Column("unit", sa.TEXT(), autoincrement=False, nullable=True), - sa.Column("category", sa.TEXT(), autoincrement=False, nullable=True), - sa.Column("short_desc", sa.TEXT(), autoincrement=False, nullable=True), - sa.PrimaryKeyConstraint("name", name="geocode_settings_pkey"), - ) - - if alembic_helpers.table_does_not_exist("bg"): - op.create_table( - "bg", - sa.Column("gid", sa.INTEGER(), autoincrement=True, nullable=False), - sa.Column( - "statefp", sa.VARCHAR(length=2), autoincrement=False, nullable=True - ), - sa.Column( - "countyfp", sa.VARCHAR(length=3), autoincrement=False, nullable=True - ), - sa.Column( - "tractce", sa.VARCHAR(length=6), autoincrement=False, nullable=True - ), - sa.Column( - "blkgrpce", sa.VARCHAR(length=1), autoincrement=False, nullable=True - ), - sa.Column( - "bg_id", sa.VARCHAR(length=12), autoincrement=False, nullable=False - ), - sa.Column( - "namelsad", sa.VARCHAR(length=13), autoincrement=False, nullable=True - ), - sa.Column( - "mtfcc", sa.VARCHAR(length=5), autoincrement=False, nullable=True - ), - sa.Column( - "funcstat", sa.VARCHAR(length=1), autoincrement=False, nullable=True - ), - sa.Column( - "aland", - sa.DOUBLE_PRECISION(precision=53), - autoincrement=False, - nullable=True, - ), - sa.Column( - "awater", - sa.DOUBLE_PRECISION(precision=53), - autoincrement=False, - nullable=True, - ), - sa.Column( - "intptlat", sa.VARCHAR(length=11), autoincrement=False, nullable=True - ), - sa.Column( - "intptlon", sa.VARCHAR(length=12), autoincrement=False, nullable=True - ), - sa.Column( - "the_geom", - geoalchemy2.types.Geometry( - spatial_index=False, - from_text="ST_GeomFromEWKT", - name="geometry", - _spatial_index_reflected=True, - ), - autoincrement=False, - nullable=True, - ), - sa.CheckConstraint( - "geometrytype(the_geom) = 'MULTIPOLYGON'::text OR the_geom IS NULL", - name="enforce_geotype_geom", - ), - sa.CheckConstraint("st_ndims(the_geom) = 2", name="enforce_dims_geom"), - sa.CheckConstraint("st_srid(the_geom) = 4269", name="enforce_srid_geom"), - sa.PrimaryKeyConstraint("bg_id", name="bg_pkey"), - comment="block groups", - ) - - if alembic_helpers.table_does_not_exist("geocode_settings_default"): - op.create_table( - "geocode_settings_default", - sa.Column("name", sa.TEXT(), autoincrement=False, nullable=False), - sa.Column("setting", sa.TEXT(), autoincrement=False, nullable=True), - sa.Column("unit", sa.TEXT(), autoincrement=False, nullable=True), - sa.Column("category", sa.TEXT(), autoincrement=False, nullable=True), - sa.Column("short_desc", sa.TEXT(), autoincrement=False, nullable=True), - sa.PrimaryKeyConstraint("name", name="geocode_settings_default_pkey"), - ) - - if alembic_helpers.table_does_not_exist("edges"): - op.create_table( - "edges", - sa.Column("gid", sa.INTEGER(), autoincrement=True, nullable=False), - sa.Column( - "statefp", sa.VARCHAR(length=2), autoincrement=False, nullable=True - ), - sa.Column( - "countyfp", sa.VARCHAR(length=3), autoincrement=False, nullable=True - ), - sa.Column("tlid", sa.BIGINT(), autoincrement=False, nullable=True), - sa.Column( - "tfidl", - sa.NUMERIC(precision=10, scale=0), - autoincrement=False, - nullable=True, - ), - sa.Column( - "tfidr", - sa.NUMERIC(precision=10, scale=0), - autoincrement=False, - nullable=True, - ), - sa.Column( - "mtfcc", sa.VARCHAR(length=5), autoincrement=False, nullable=True - ), - sa.Column( - "fullname", sa.VARCHAR(length=100), autoincrement=False, nullable=True - ), - sa.Column( - "smid", sa.VARCHAR(length=22), autoincrement=False, nullable=True - ), - sa.Column( - "lfromadd", sa.VARCHAR(length=12), autoincrement=False, nullable=True - ), - sa.Column( - "ltoadd", sa.VARCHAR(length=12), autoincrement=False, nullable=True - ), - sa.Column( - "rfromadd", sa.VARCHAR(length=12), autoincrement=False, nullable=True - ), - sa.Column( - "rtoadd", sa.VARCHAR(length=12), autoincrement=False, nullable=True - ), - sa.Column("zipl", sa.VARCHAR(length=5), autoincrement=False, nullable=True), - sa.Column("zipr", sa.VARCHAR(length=5), autoincrement=False, nullable=True), - sa.Column( - "featcat", sa.VARCHAR(length=1), autoincrement=False, nullable=True - ), - sa.Column( - "hydroflg", sa.VARCHAR(length=1), autoincrement=False, nullable=True - ), - sa.Column( - "railflg", sa.VARCHAR(length=1), autoincrement=False, nullable=True - ), - sa.Column( - "roadflg", sa.VARCHAR(length=1), autoincrement=False, nullable=True - ), - sa.Column( - "olfflg", sa.VARCHAR(length=1), autoincrement=False, nullable=True - ), - sa.Column( - "passflg", sa.VARCHAR(length=1), autoincrement=False, nullable=True - ), - sa.Column( - "divroad", sa.VARCHAR(length=1), autoincrement=False, nullable=True - ), - sa.Column( - "exttyp", sa.VARCHAR(length=1), autoincrement=False, nullable=True - ), - sa.Column("ttyp", sa.VARCHAR(length=1), autoincrement=False, nullable=True), - sa.Column( - "deckedroad", sa.VARCHAR(length=1), autoincrement=False, nullable=True - ), - sa.Column( - "artpath", sa.VARCHAR(length=1), autoincrement=False, nullable=True - ), - sa.Column( - "persist", sa.VARCHAR(length=1), autoincrement=False, nullable=True - ), - sa.Column( - "gcseflg", sa.VARCHAR(length=1), autoincrement=False, nullable=True - ), - sa.Column( - "offsetl", sa.VARCHAR(length=1), autoincrement=False, nullable=True - ), - sa.Column( - "offsetr", sa.VARCHAR(length=1), autoincrement=False, nullable=True - ), - sa.Column( - "tnidf", - sa.NUMERIC(precision=10, scale=0), - autoincrement=False, - nullable=True, - ), - sa.Column( - "tnidt", - sa.NUMERIC(precision=10, scale=0), - autoincrement=False, - nullable=True, - ), - sa.Column( - "the_geom", - geoalchemy2.types.Geometry( - from_text="ST_GeomFromEWKT", - name="geometry", - _spatial_index_reflected=True, - ), - autoincrement=False, - nullable=True, - ), - sa.CheckConstraint( - "geometrytype(the_geom) = 'MULTILINESTRING'::text OR the_geom IS NULL", - name="enforce_geotype_the_geom", - ), - sa.CheckConstraint("st_ndims(the_geom) = 2", name="enforce_dims_the_geom"), - sa.CheckConstraint( - "st_srid(the_geom) = 4269", name="enforce_srid_the_geom" - ), - sa.PrimaryKeyConstraint("gid", name="edges_pkey"), - ) - op.create_index( - "idx_tiger_edges_the_geom_gist", - "edges", - ["the_geom"], - unique=False, - postgresql_using="gist", - ) - op.create_index("idx_tiger_edges_countyfp", "edges", ["countyfp"], unique=False) - op.create_index("idx_edges_tlid", "edges", ["tlid"], unique=False) - - if alembic_helpers.table_does_not_exist("faces"): - op.create_table( - "faces", - sa.Column("gid", sa.INTEGER(), autoincrement=True, nullable=False), - sa.Column( - "tfid", - sa.NUMERIC(precision=10, scale=0), - autoincrement=False, - nullable=True, - ), - sa.Column( - "statefp00", sa.VARCHAR(length=2), autoincrement=False, nullable=True - ), - sa.Column( - "countyfp00", sa.VARCHAR(length=3), autoincrement=False, nullable=True - ), - sa.Column( - "tractce00", sa.VARCHAR(length=6), autoincrement=False, nullable=True - ), - sa.Column( - "blkgrpce00", sa.VARCHAR(length=1), autoincrement=False, nullable=True - ), - sa.Column( - "blockce00", sa.VARCHAR(length=4), autoincrement=False, nullable=True - ), - sa.Column( - "cousubfp00", sa.VARCHAR(length=5), autoincrement=False, nullable=True - ), - sa.Column( - "submcdfp00", sa.VARCHAR(length=5), autoincrement=False, nullable=True - ), - sa.Column( - "conctyfp00", sa.VARCHAR(length=5), autoincrement=False, nullable=True - ), - sa.Column( - "placefp00", sa.VARCHAR(length=5), autoincrement=False, nullable=True - ), - sa.Column( - "aiannhfp00", sa.VARCHAR(length=5), autoincrement=False, nullable=True - ), - sa.Column( - "aiannhce00", sa.VARCHAR(length=4), autoincrement=False, nullable=True - ), - sa.Column( - "comptyp00", sa.VARCHAR(length=1), autoincrement=False, nullable=True - ), - sa.Column( - "trsubfp00", sa.VARCHAR(length=5), autoincrement=False, nullable=True - ), - sa.Column( - "trsubce00", sa.VARCHAR(length=3), autoincrement=False, nullable=True - ), - sa.Column( - "anrcfp00", sa.VARCHAR(length=5), autoincrement=False, nullable=True - ), - sa.Column( - "elsdlea00", sa.VARCHAR(length=5), autoincrement=False, nullable=True - ), - sa.Column( - "scsdlea00", sa.VARCHAR(length=5), autoincrement=False, nullable=True - ), - sa.Column( - "unsdlea00", sa.VARCHAR(length=5), autoincrement=False, nullable=True - ), - sa.Column( - "uace00", sa.VARCHAR(length=5), autoincrement=False, nullable=True - ), - sa.Column( - "cd108fp", sa.VARCHAR(length=2), autoincrement=False, nullable=True - ), - sa.Column( - "sldust00", sa.VARCHAR(length=3), autoincrement=False, nullable=True - ), - sa.Column( - "sldlst00", sa.VARCHAR(length=3), autoincrement=False, nullable=True - ), - sa.Column( - "vtdst00", sa.VARCHAR(length=6), autoincrement=False, nullable=True - ), - sa.Column( - "zcta5ce00", sa.VARCHAR(length=5), autoincrement=False, nullable=True - ), - sa.Column( - "tazce00", sa.VARCHAR(length=6), autoincrement=False, nullable=True - ), - sa.Column( - "ugace00", sa.VARCHAR(length=5), autoincrement=False, nullable=True - ), - sa.Column( - "puma5ce00", sa.VARCHAR(length=5), autoincrement=False, nullable=True - ), - sa.Column( - "statefp", sa.VARCHAR(length=2), autoincrement=False, nullable=True - ), - sa.Column( - "countyfp", sa.VARCHAR(length=3), autoincrement=False, nullable=True - ), - sa.Column( - "tractce", sa.VARCHAR(length=6), autoincrement=False, nullable=True - ), - sa.Column( - "blkgrpce", sa.VARCHAR(length=1), autoincrement=False, nullable=True - ), - sa.Column( - "blockce", sa.VARCHAR(length=4), autoincrement=False, nullable=True - ), - sa.Column( - "cousubfp", sa.VARCHAR(length=5), autoincrement=False, nullable=True - ), - sa.Column( - "submcdfp", sa.VARCHAR(length=5), autoincrement=False, nullable=True - ), - sa.Column( - "conctyfp", sa.VARCHAR(length=5), autoincrement=False, nullable=True - ), - sa.Column( - "placefp", sa.VARCHAR(length=5), autoincrement=False, nullable=True - ), - sa.Column( - "aiannhfp", sa.VARCHAR(length=5), autoincrement=False, nullable=True - ), - sa.Column( - "aiannhce", sa.VARCHAR(length=4), autoincrement=False, nullable=True - ), - sa.Column( - "comptyp", sa.VARCHAR(length=1), autoincrement=False, nullable=True - ), - sa.Column( - "trsubfp", sa.VARCHAR(length=5), autoincrement=False, nullable=True - ), - sa.Column( - "trsubce", sa.VARCHAR(length=3), autoincrement=False, nullable=True - ), - sa.Column( - "anrcfp", sa.VARCHAR(length=5), autoincrement=False, nullable=True - ), - sa.Column( - "ttractce", sa.VARCHAR(length=6), autoincrement=False, nullable=True - ), - sa.Column( - "tblkgpce", sa.VARCHAR(length=1), autoincrement=False, nullable=True - ), - sa.Column( - "elsdlea", sa.VARCHAR(length=5), autoincrement=False, nullable=True - ), - sa.Column( - "scsdlea", sa.VARCHAR(length=5), autoincrement=False, nullable=True - ), - sa.Column( - "unsdlea", sa.VARCHAR(length=5), autoincrement=False, nullable=True - ), - sa.Column("uace", sa.VARCHAR(length=5), autoincrement=False, nullable=True), - sa.Column( - "cd111fp", sa.VARCHAR(length=2), autoincrement=False, nullable=True - ), - sa.Column( - "sldust", sa.VARCHAR(length=3), autoincrement=False, nullable=True - ), - sa.Column( - "sldlst", sa.VARCHAR(length=3), autoincrement=False, nullable=True - ), - sa.Column( - "vtdst", sa.VARCHAR(length=6), autoincrement=False, nullable=True - ), - sa.Column( - "zcta5ce", sa.VARCHAR(length=5), autoincrement=False, nullable=True - ), - sa.Column( - "tazce", sa.VARCHAR(length=6), autoincrement=False, nullable=True - ), - sa.Column( - "ugace", sa.VARCHAR(length=5), autoincrement=False, nullable=True - ), - sa.Column( - "puma5ce", sa.VARCHAR(length=5), autoincrement=False, nullable=True - ), - sa.Column( - "csafp", sa.VARCHAR(length=3), autoincrement=False, nullable=True - ), - sa.Column( - "cbsafp", sa.VARCHAR(length=5), autoincrement=False, nullable=True - ), - sa.Column( - "metdivfp", sa.VARCHAR(length=5), autoincrement=False, nullable=True - ), - sa.Column( - "cnectafp", sa.VARCHAR(length=3), autoincrement=False, nullable=True - ), - sa.Column( - "nectafp", sa.VARCHAR(length=5), autoincrement=False, nullable=True - ), - sa.Column( - "nctadvfp", sa.VARCHAR(length=5), autoincrement=False, nullable=True - ), - sa.Column( - "lwflag", sa.VARCHAR(length=1), autoincrement=False, nullable=True - ), - sa.Column( - "offset", sa.VARCHAR(length=1), autoincrement=False, nullable=True - ), - sa.Column( - "atotal", - sa.DOUBLE_PRECISION(precision=53), - autoincrement=False, - nullable=True, - ), - sa.Column( - "intptlat", sa.VARCHAR(length=11), autoincrement=False, nullable=True - ), - sa.Column( - "intptlon", sa.VARCHAR(length=12), autoincrement=False, nullable=True - ), - sa.Column( - "the_geom", - geoalchemy2.types.Geometry( - from_text="ST_GeomFromEWKT", - name="geometry", - _spatial_index_reflected=True, - ), - autoincrement=False, - nullable=True, - ), - sa.Column( - "tractce20", sa.VARCHAR(length=6), autoincrement=False, nullable=True - ), - sa.Column( - "blkgrpce20", sa.VARCHAR(length=1), autoincrement=False, nullable=True - ), - sa.Column( - "blockce20", sa.VARCHAR(length=4), autoincrement=False, nullable=True - ), - sa.Column( - "countyfp20", sa.VARCHAR(length=3), autoincrement=False, nullable=True - ), - sa.Column( - "statefp20", sa.VARCHAR(length=2), autoincrement=False, nullable=True - ), - sa.CheckConstraint( - "geometrytype(the_geom) = 'MULTIPOLYGON'::text OR the_geom IS NULL", - name="enforce_geotype_the_geom", - ), - sa.CheckConstraint("st_ndims(the_geom) = 2", name="enforce_dims_the_geom"), - sa.CheckConstraint( - "st_srid(the_geom) = 4269", name="enforce_srid_the_geom" - ), - sa.PrimaryKeyConstraint("gid", name="faces_pkey"), - ) - op.create_index( - "tiger_faces_the_geom_gist", - "faces", - ["the_geom"], - unique=False, - postgresql_using="gist", - ) - op.create_index("idx_tiger_faces_tfid", "faces", ["tfid"], unique=False) - op.create_index("idx_tiger_faces_countyfp", "faces", ["countyfp"], unique=False) - - if alembic_helpers.table_does_not_exist("loader_variables"): - op.create_table( - "loader_variables", - sa.Column( - "tiger_year", sa.VARCHAR(length=4), autoincrement=False, nullable=False - ), - sa.Column("website_root", sa.TEXT(), autoincrement=False, nullable=True), - sa.Column("staging_fold", sa.TEXT(), autoincrement=False, nullable=True), - sa.Column("data_schema", sa.TEXT(), autoincrement=False, nullable=True), - sa.Column("staging_schema", sa.TEXT(), autoincrement=False, nullable=True), - sa.PrimaryKeyConstraint("tiger_year", name="loader_variables_pkey"), - ) - - if alembic_helpers.table_does_not_exist("county"): - op.create_table( - "county", - sa.Column("gid", sa.INTEGER(), autoincrement=True, nullable=False), - sa.Column( - "statefp", sa.VARCHAR(length=2), autoincrement=False, nullable=True - ), - sa.Column( - "countyfp", sa.VARCHAR(length=3), autoincrement=False, nullable=True - ), - sa.Column( - "countyns", sa.VARCHAR(length=8), autoincrement=False, nullable=True - ), - sa.Column( - "cntyidfp", sa.VARCHAR(length=5), autoincrement=False, nullable=False - ), - sa.Column( - "name", sa.VARCHAR(length=100), autoincrement=False, nullable=True - ), - sa.Column( - "namelsad", sa.VARCHAR(length=100), autoincrement=False, nullable=True - ), - sa.Column("lsad", sa.VARCHAR(length=2), autoincrement=False, nullable=True), - sa.Column( - "classfp", sa.VARCHAR(length=2), autoincrement=False, nullable=True - ), - sa.Column( - "mtfcc", sa.VARCHAR(length=5), autoincrement=False, nullable=True - ), - sa.Column( - "csafp", sa.VARCHAR(length=3), autoincrement=False, nullable=True - ), - sa.Column( - "cbsafp", sa.VARCHAR(length=5), autoincrement=False, nullable=True - ), - sa.Column( - "metdivfp", sa.VARCHAR(length=5), autoincrement=False, nullable=True - ), - sa.Column( - "funcstat", sa.VARCHAR(length=1), autoincrement=False, nullable=True - ), - sa.Column("aland", sa.BIGINT(), autoincrement=False, nullable=True), - sa.Column( - "awater", - sa.DOUBLE_PRECISION(precision=53), - autoincrement=False, - nullable=True, - ), - sa.Column( - "intptlat", sa.VARCHAR(length=11), autoincrement=False, nullable=True - ), - sa.Column( - "intptlon", sa.VARCHAR(length=12), autoincrement=False, nullable=True - ), - sa.Column( - "the_geom", - geoalchemy2.types.Geometry( - spatial_index=False, - from_text="ST_GeomFromEWKT", - name="geometry", - _spatial_index_reflected=True, - ), - autoincrement=False, - nullable=True, - ), - sa.CheckConstraint( - "geometrytype(the_geom) = 'MULTIPOLYGON'::text OR the_geom IS NULL", - name="enforce_geotype_geom", - ), - sa.CheckConstraint("st_ndims(the_geom) = 2", name="enforce_dims_geom"), - sa.CheckConstraint("st_srid(the_geom) = 4269", name="enforce_srid_geom"), - sa.PrimaryKeyConstraint("cntyidfp", name="pk_tiger_county"), - sa.UniqueConstraint("gid", name="uidx_county_gid"), - ) - op.create_index("idx_tiger_county", "county", ["countyfp"], unique=False) - - if alembic_helpers.table_does_not_exist("zip_lookup_base"): - op.create_table( - "zip_lookup_base", - sa.Column("zip", sa.VARCHAR(length=5), autoincrement=False, nullable=False), - sa.Column( - "state", sa.VARCHAR(length=40), autoincrement=False, nullable=True - ), - sa.Column( - "county", sa.VARCHAR(length=90), autoincrement=False, nullable=True - ), - sa.Column( - "city", sa.VARCHAR(length=90), autoincrement=False, nullable=True - ), - sa.Column( - "statefp", sa.VARCHAR(length=2), autoincrement=False, nullable=True - ), - sa.PrimaryKeyConstraint("zip", name="zip_lookup_base_pkey"), - ) - - if alembic_helpers.table_does_not_exist("tract"): - op.create_table( - "tract", - sa.Column("gid", sa.INTEGER(), autoincrement=True, nullable=False), - sa.Column( - "statefp", sa.VARCHAR(length=2), autoincrement=False, nullable=True - ), - sa.Column( - "countyfp", sa.VARCHAR(length=3), autoincrement=False, nullable=True - ), - sa.Column( - "tractce", sa.VARCHAR(length=6), autoincrement=False, nullable=True - ), - sa.Column( - "tract_id", sa.VARCHAR(length=11), autoincrement=False, nullable=False - ), - sa.Column("name", sa.VARCHAR(length=7), autoincrement=False, nullable=True), - sa.Column( - "namelsad", sa.VARCHAR(length=20), autoincrement=False, nullable=True - ), - sa.Column( - "mtfcc", sa.VARCHAR(length=5), autoincrement=False, nullable=True - ), - sa.Column( - "funcstat", sa.VARCHAR(length=1), autoincrement=False, nullable=True - ), - sa.Column( - "aland", - sa.DOUBLE_PRECISION(precision=53), - autoincrement=False, - nullable=True, - ), - sa.Column( - "awater", - sa.DOUBLE_PRECISION(precision=53), - autoincrement=False, - nullable=True, - ), - sa.Column( - "intptlat", sa.VARCHAR(length=11), autoincrement=False, nullable=True - ), - sa.Column( - "intptlon", sa.VARCHAR(length=12), autoincrement=False, nullable=True - ), - sa.Column( - "the_geom", - geoalchemy2.types.Geometry( - spatial_index=False, - from_text="ST_GeomFromEWKT", - name="geometry", - _spatial_index_reflected=True, - ), - autoincrement=False, - nullable=True, - ), - sa.CheckConstraint( - "geometrytype(the_geom) = 'MULTIPOLYGON'::text OR the_geom IS NULL", - name="enforce_geotype_geom", - ), - sa.CheckConstraint("st_ndims(the_geom) = 2", name="enforce_dims_geom"), - sa.CheckConstraint("st_srid(the_geom) = 4269", name="enforce_srid_geom"), - sa.PrimaryKeyConstraint("tract_id", name="tract_pkey"), - ) - - if alembic_helpers.table_does_not_exist("layer"): - op.create_table( - "layer", - sa.Column("topology_id", sa.INTEGER(), autoincrement=False, nullable=False), - sa.Column("layer_id", sa.INTEGER(), autoincrement=False, nullable=False), - sa.Column("schema_name", sa.VARCHAR(), autoincrement=False, nullable=False), - sa.Column("table_name", sa.VARCHAR(), autoincrement=False, nullable=False), - sa.Column( - "feature_column", sa.VARCHAR(), autoincrement=False, nullable=False - ), - sa.Column( - "feature_type", sa.INTEGER(), autoincrement=False, nullable=False - ), - sa.Column( - "level", - sa.INTEGER(), - server_default=sa.text("0"), - autoincrement=False, - nullable=False, - ), - sa.Column("child_id", sa.INTEGER(), autoincrement=False, nullable=True), - sa.ForeignKeyConstraint( - ["topology_id"], ["topology.id"], name="layer_topology_id_fkey" - ), - sa.PrimaryKeyConstraint("topology_id", "layer_id", name="layer_pkey"), - sa.UniqueConstraint( - "schema_name", - "table_name", - "feature_column", - name="layer_schema_name_table_name_feature_column_key", - ), - ) - - if alembic_helpers.table_does_not_exist("street_type_lookup"): - op.create_table( - "street_type_lookup", - sa.Column( - "name", sa.VARCHAR(length=50), autoincrement=False, nullable=False - ), - sa.Column( - "abbrev", sa.VARCHAR(length=50), autoincrement=False, nullable=True - ), - sa.Column( - "is_hw", - sa.BOOLEAN(), - server_default=sa.text("false"), - autoincrement=False, - nullable=False, - ), - sa.PrimaryKeyConstraint("name", name="street_type_lookup_pkey"), - ) - op.create_index( - "street_type_lookup_abbrev_idx", - "street_type_lookup", - ["abbrev"], - unique=False, - ) - - if alembic_helpers.table_does_not_exist("taskpolygons"): - op.create_table( - "taskpolygons", - sa.Column( - "geom", - geoalchemy2.types.Geometry( - from_text="ST_GeomFromEWKT", - name="geometry", - _spatial_index_reflected=True, - ), - autoincrement=False, - nullable=True, - ), - sa.Column("clusteruid", sa.TEXT(), autoincrement=False, nullable=True), - ) - op.create_index( - "taskpolygons_idx", - "taskpolygons", - ["geom"], - unique=False, - postgresql_using="gist", - ) - - if alembic_helpers.table_does_not_exist("tabblock"): - op.create_table( - "tabblock", - sa.Column("gid", sa.INTEGER(), autoincrement=True, nullable=False), - sa.Column( - "statefp", sa.VARCHAR(length=2), autoincrement=False, nullable=True - ), - sa.Column( - "countyfp", sa.VARCHAR(length=3), autoincrement=False, nullable=True - ), - sa.Column( - "tractce", sa.VARCHAR(length=6), autoincrement=False, nullable=True - ), - sa.Column( - "blockce", sa.VARCHAR(length=4), autoincrement=False, nullable=True - ), - sa.Column( - "tabblock_id", - sa.VARCHAR(length=16), - autoincrement=False, - nullable=False, - ), - sa.Column( - "name", sa.VARCHAR(length=20), autoincrement=False, nullable=True - ), - sa.Column( - "mtfcc", sa.VARCHAR(length=5), autoincrement=False, nullable=True - ), - sa.Column("ur", sa.VARCHAR(length=1), autoincrement=False, nullable=True), - sa.Column("uace", sa.VARCHAR(length=5), autoincrement=False, nullable=True), - sa.Column( - "funcstat", sa.VARCHAR(length=1), autoincrement=False, nullable=True - ), - sa.Column( - "aland", - sa.DOUBLE_PRECISION(precision=53), - autoincrement=False, - nullable=True, - ), - sa.Column( - "awater", - sa.DOUBLE_PRECISION(precision=53), - autoincrement=False, - nullable=True, - ), - sa.Column( - "intptlat", sa.VARCHAR(length=11), autoincrement=False, nullable=True - ), - sa.Column( - "intptlon", sa.VARCHAR(length=12), autoincrement=False, nullable=True - ), - sa.Column( - "the_geom", - geoalchemy2.types.Geometry( - spatial_index=False, - from_text="ST_GeomFromEWKT", - name="geometry", - _spatial_index_reflected=True, - ), - autoincrement=False, - nullable=True, - ), - sa.CheckConstraint( - "geometrytype(the_geom) = 'MULTIPOLYGON'::text OR the_geom IS NULL", - name="enforce_geotype_geom", - ), - sa.CheckConstraint("st_ndims(the_geom) = 2", name="enforce_dims_geom"), - sa.CheckConstraint("st_srid(the_geom) = 4269", name="enforce_srid_geom"), - sa.PrimaryKeyConstraint("tabblock_id", name="tabblock_pkey"), - ) - - if alembic_helpers.table_does_not_exist("countysub_lookup"): - op.create_table( - "countysub_lookup", - sa.Column("st_code", sa.INTEGER(), autoincrement=False, nullable=False), - sa.Column( - "state", sa.VARCHAR(length=2), autoincrement=False, nullable=True - ), - sa.Column("co_code", sa.INTEGER(), autoincrement=False, nullable=False), - sa.Column( - "county", sa.VARCHAR(length=90), autoincrement=False, nullable=True - ), - sa.Column("cs_code", sa.INTEGER(), autoincrement=False, nullable=False), - sa.Column( - "name", sa.VARCHAR(length=90), autoincrement=False, nullable=True - ), - sa.PrimaryKeyConstraint( - "st_code", "co_code", "cs_code", name="countysub_lookup_pkey" - ), - ) - op.create_index( - "countysub_lookup_state_idx", "countysub_lookup", ["state"], unique=False - ) - op.create_index( - "countysub_lookup_name_idx", - "countysub_lookup", - [sa.text("soundex(name::text)")], - unique=False, - ) - - if alembic_helpers.table_does_not_exist("addr"): - op.create_table( - "addr", - sa.Column("gid", sa.INTEGER(), autoincrement=True, nullable=False), - sa.Column("tlid", sa.BIGINT(), autoincrement=False, nullable=True), - sa.Column( - "fromhn", sa.VARCHAR(length=12), autoincrement=False, nullable=True - ), - sa.Column( - "tohn", sa.VARCHAR(length=12), autoincrement=False, nullable=True - ), - sa.Column("side", sa.VARCHAR(length=1), autoincrement=False, nullable=True), - sa.Column("zip", sa.VARCHAR(length=5), autoincrement=False, nullable=True), - sa.Column( - "plus4", sa.VARCHAR(length=4), autoincrement=False, nullable=True - ), - sa.Column( - "fromtyp", sa.VARCHAR(length=1), autoincrement=False, nullable=True - ), - sa.Column( - "totyp", sa.VARCHAR(length=1), autoincrement=False, nullable=True - ), - sa.Column("fromarmid", sa.INTEGER(), autoincrement=False, nullable=True), - sa.Column("toarmid", sa.INTEGER(), autoincrement=False, nullable=True), - sa.Column( - "arid", sa.VARCHAR(length=22), autoincrement=False, nullable=True - ), - sa.Column( - "mtfcc", sa.VARCHAR(length=5), autoincrement=False, nullable=True - ), - sa.Column( - "statefp", sa.VARCHAR(length=2), autoincrement=False, nullable=True - ), - sa.PrimaryKeyConstraint("gid", name="addr_pkey"), - ) - op.create_index("idx_tiger_addr_zip", "addr", ["zip"], unique=False) - op.create_index( - "idx_tiger_addr_tlid_statefp", "addr", ["tlid", "statefp"], unique=False - ) - - if alembic_helpers.table_does_not_exist("voronois"): - op.create_table( - "voronois", - sa.Column("clusteruid", sa.TEXT(), autoincrement=False, nullable=True), - sa.Column( - "geom", - geoalchemy2.types.Geometry( - from_text="ST_GeomFromEWKT", - name="geometry", - _spatial_index_reflected=True, - ), - autoincrement=False, - nullable=True, - ), - ) - op.create_index( - "voronois_idx", "voronois", ["geom"], unique=False, postgresql_using="gist" - ) - - if alembic_helpers.table_does_not_exist("state"): - op.create_table( - "state", - sa.Column("gid", sa.INTEGER(), autoincrement=True, nullable=False), - sa.Column( - "region", sa.VARCHAR(length=2), autoincrement=False, nullable=True - ), - sa.Column( - "division", sa.VARCHAR(length=2), autoincrement=False, nullable=True - ), - sa.Column( - "statefp", sa.VARCHAR(length=2), autoincrement=False, nullable=False - ), - sa.Column( - "statens", sa.VARCHAR(length=8), autoincrement=False, nullable=True - ), - sa.Column( - "stusps", sa.VARCHAR(length=2), autoincrement=False, nullable=False - ), - sa.Column( - "name", sa.VARCHAR(length=100), autoincrement=False, nullable=True - ), - sa.Column("lsad", sa.VARCHAR(length=2), autoincrement=False, nullable=True), - sa.Column( - "mtfcc", sa.VARCHAR(length=5), autoincrement=False, nullable=True - ), - sa.Column( - "funcstat", sa.VARCHAR(length=1), autoincrement=False, nullable=True - ), - sa.Column("aland", sa.BIGINT(), autoincrement=False, nullable=True), - sa.Column("awater", sa.BIGINT(), autoincrement=False, nullable=True), - sa.Column( - "intptlat", sa.VARCHAR(length=11), autoincrement=False, nullable=True - ), - sa.Column( - "intptlon", sa.VARCHAR(length=12), autoincrement=False, nullable=True - ), - sa.Column( - "the_geom", - geoalchemy2.types.Geometry( - from_text="ST_GeomFromEWKT", - name="geometry", - _spatial_index_reflected=True, - ), - autoincrement=False, - nullable=True, - ), - sa.CheckConstraint( - "geometrytype(the_geom) = 'MULTIPOLYGON'::text OR the_geom IS NULL", - name="enforce_geotype_the_geom", - ), - sa.CheckConstraint("st_ndims(the_geom) = 2", name="enforce_dims_the_geom"), - sa.CheckConstraint( - "st_srid(the_geom) = 4269", name="enforce_srid_the_geom" - ), - sa.PrimaryKeyConstraint("statefp", name="pk_tiger_state"), - sa.UniqueConstraint("gid", name="uidx_tiger_state_gid"), - sa.UniqueConstraint("stusps", name="uidx_tiger_state_stusps"), - ) - op.create_index( - "idx_tiger_state_the_geom_gist", - "state", - ["the_geom"], - unique=False, - postgresql_using="gist", - ) - - if alembic_helpers.table_does_not_exist("clusteredbuildings"): - op.create_table( - "clusteredbuildings", - sa.Column("id", sa.INTEGER(), autoincrement=False, nullable=True), - sa.Column("project_id", sa.VARCHAR(), autoincrement=False, nullable=True), - sa.Column("osm_id", sa.VARCHAR(), autoincrement=False, nullable=True), - sa.Column( - "geom", - geoalchemy2.types.Geometry( - geometry_type="POLYGON", - srid=4326, - from_text="ST_GeomFromEWKT", - name="geometry", - _spatial_index_reflected=True, - ), - autoincrement=False, - nullable=True, - ), - sa.Column( - "tags", - postgresql.JSONB(astext_type=sa.Text()), - autoincrement=False, - nullable=True, - ), - sa.Column("polyid", sa.BIGINT(), autoincrement=False, nullable=True), - sa.Column("numfeatures", sa.BIGINT(), autoincrement=False, nullable=True), - sa.Column("cid", sa.INTEGER(), autoincrement=False, nullable=True), - sa.Column("clusteruid", sa.TEXT(), autoincrement=False, nullable=True), - ) - op.create_index( - "clusteredbuildings_idx", - "clusteredbuildings", - ["geom"], - unique=False, - postgresql_using="gist", - ) - - if alembic_helpers.table_does_not_exist("loader_lookuptables"): - op.create_table( - "loader_lookuptables", - sa.Column( - "process_order", - sa.INTEGER(), - server_default=sa.text("1000"), - autoincrement=False, - nullable=False, - ), - sa.Column( - "lookup_name", - sa.TEXT(), - autoincrement=False, - nullable=False, - comment="This is the table name to inherit from and suffix of resulting output table -- how the table will be named -- edges here would mean -- ma_edges , pa_edges etc. except in the case of national tables. national level tables have no prefix", - ), - sa.Column( - "table_name", - sa.TEXT(), - autoincrement=False, - nullable=True, - comment="suffix of the tables to load e.g. edges would load all tables like *edges.dbf(shp) -- so tl_2010_42129_edges.dbf . ", - ), - sa.Column( - "single_mode", - sa.BOOLEAN(), - server_default=sa.text("true"), - autoincrement=False, - nullable=False, - ), - sa.Column( - "load", - sa.BOOLEAN(), - server_default=sa.text("true"), - autoincrement=False, - nullable=False, - comment="Whether or not to load the table. For states and zcta5 (you may just want to download states10, zcta510 nationwide file manually) load your own into a single table that inherits from tiger.states, tiger.zcta5. You'll get improved performance for some geocoding cases.", - ), - sa.Column( - "level_county", - sa.BOOLEAN(), - server_default=sa.text("false"), - autoincrement=False, - nullable=False, - ), - sa.Column( - "level_state", - sa.BOOLEAN(), - server_default=sa.text("false"), - autoincrement=False, - nullable=False, - ), - sa.Column( - "level_nation", - sa.BOOLEAN(), - server_default=sa.text("false"), - autoincrement=False, - nullable=False, - comment="These are tables that contain all data for the whole US so there is just a single file", - ), - sa.Column( - "post_load_process", sa.TEXT(), autoincrement=False, nullable=True - ), - sa.Column( - "single_geom_mode", - sa.BOOLEAN(), - server_default=sa.text("false"), - autoincrement=False, - nullable=True, - ), - sa.Column( - "insert_mode", - sa.CHAR(length=1), - server_default=sa.text("'c'::bpchar"), - autoincrement=False, - nullable=False, - ), - sa.Column( - "pre_load_process", sa.TEXT(), autoincrement=False, nullable=True - ), - sa.Column( - "columns_exclude", - postgresql.ARRAY(sa.TEXT()), - autoincrement=False, - nullable=True, - comment="List of columns to exclude as an array. This is excluded from both input table and output table and rest of columns remaining are assumed to be in same order in both tables. gid, geoid,cpi,suffix1ce are excluded if no columns are specified.", - ), - sa.Column( - "website_root_override", - sa.TEXT(), - autoincrement=False, - nullable=True, - comment="Path to use for wget instead of that specified in year table. Needed currently for zcta where they release that only for 2000 and 2010", - ), - sa.PrimaryKeyConstraint("lookup_name", name="loader_lookuptables_pkey"), - ) - - # ### end Alembic commands ### - - -def downgrade() -> None: - # ### commands auto generated by Alembic - please adjust! ### - op.drop_table("loader_lookuptables") - op.drop_index( - "clusteredbuildings_idx", - table_name="clusteredbuildings", - postgresql_using="gist", - ) - op.drop_table("clusteredbuildings") - op.drop_index( - "idx_tiger_state_the_geom_gist", table_name="state", postgresql_using="gist" - ) - op.drop_table("state") - op.drop_index("voronois_idx", table_name="voronois", postgresql_using="gist") - op.drop_table("voronois") - op.drop_index("idx_tiger_addr_tlid_statefp", table_name="addr") - op.drop_index("idx_tiger_addr_zip", table_name="addr") - op.drop_table("addr") - op.drop_index("countysub_lookup_name_idx", table_name="countysub_lookup") - op.drop_index("countysub_lookup_state_idx", table_name="countysub_lookup") - op.drop_table("countysub_lookup") - op.drop_table("tabblock") - op.drop_index( - "taskpolygons_idx", table_name="taskpolygons", postgresql_using="gist" - ) - op.drop_table("taskpolygons") - op.drop_index("street_type_lookup_abbrev_idx", table_name="street_type_lookup") - op.drop_table("street_type_lookup") - op.drop_table("layer") - op.drop_table("tract") - op.drop_table("zip_lookup_base") - op.drop_index("idx_tiger_county", table_name="county") - op.drop_table("county") - op.drop_table("loader_variables") - op.drop_index("idx_tiger_faces_countyfp", table_name="faces") - op.drop_index("idx_tiger_faces_tfid", table_name="faces") - op.drop_index( - "tiger_faces_the_geom_gist", table_name="faces", postgresql_using="gist" - ) - op.drop_table("faces") - op.drop_index("idx_edges_tlid", table_name="edges") - op.drop_index("idx_tiger_edges_countyfp", table_name="edges") - op.drop_index( - "idx_tiger_edges_the_geom_gist", table_name="edges", postgresql_using="gist" - ) - op.drop_table("edges") - op.drop_table("geocode_settings_default") - op.drop_table("bg") - op.drop_table("geocode_settings") - op.drop_index("county_lookup_name_idx", table_name="county_lookup") - op.drop_index("county_lookup_state_idx", table_name="county_lookup") - op.drop_table("county_lookup") - op.drop_table("zip_lookup") - op.drop_table("zip_state_loc") - op.drop_index( - "tiger_place_the_geom_gist", table_name="place", postgresql_using="gist" - ) - op.drop_table("place") - op.drop_index( - "lowfeaturecountpolygons_idx", - table_name="lowfeaturecountpolygons", - postgresql_using="gist", - ) - op.drop_table("lowfeaturecountpolygons") - op.drop_index("place_lookup_name_idx", table_name="place_lookup") - op.drop_index("place_lookup_state_idx", table_name="place_lookup") - op.drop_table("place_lookup") - op.drop_table("zip_state") - op.drop_index( - "tige_cousub_the_geom_gist", table_name="cousub", postgresql_using="gist" - ) - op.drop_table("cousub") - op.drop_index( - "splitpolygons_idx", table_name="splitpolygons", postgresql_using="gist" - ) - op.drop_table("splitpolygons") - op.drop_table("tabblock20") - op.drop_table("state_lookup") - op.drop_index("direction_lookup_abbrev_idx", table_name="direction_lookup") - op.drop_table("direction_lookup") - op.drop_table("pagc_gaz") - op.drop_index( - "secondary_unit_lookup_abbrev_idx", table_name="secondary_unit_lookup" - ) - op.drop_table("secondary_unit_lookup") - op.drop_table("zcta5") - op.drop_index("buildings_idx", table_name="buildings", postgresql_using="gist") - op.drop_table("buildings") - op.drop_index("idx_tiger_featnames_lname", table_name="featnames") - op.drop_index("idx_tiger_featnames_snd_name", table_name="featnames") - op.drop_index("idx_tiger_featnames_tlid_statefp", table_name="featnames") - op.drop_table("featnames") - op.drop_table("topology") - op.drop_index( - "idx_addrfeat_geom_gist", table_name="addrfeat", postgresql_using="gist" - ) - op.drop_index("idx_addrfeat_tlid", table_name="addrfeat") - op.drop_index("idx_addrfeat_zipl", table_name="addrfeat") - op.drop_index("idx_addrfeat_zipr", table_name="addrfeat") - op.drop_table("addrfeat") - op.drop_table("pagc_rules") - op.drop_table("zip_lookup_all") - op.drop_table("pagc_lex") - op.drop_index( - "dumpedpoints_idx", table_name="dumpedpoints", postgresql_using="gist" - ) - op.drop_table("dumpedpoints") - op.drop_table("loader_platform") - # ### end Alembic commands ### diff --git a/src/backend/pdm.lock b/src/backend/pdm.lock index 938fe14508..68f010ab90 100644 --- a/src/backend/pdm.lock +++ b/src/backend/pdm.lock @@ -6,22 +6,7 @@ groups = ["default", "test", "dev", "docs", "debug"] cross_platform = true static_urls = false lock_version = "4.3" -content_hash = "sha256:f074e7e235d93874f1308bcdbdd80f830ce811de6b151534b4ca6e768c3cae41" - -[[package]] -name = "alembic" -version = "1.12.0" -requires_python = ">=3.7" -summary = "A database migration tool for SQLAlchemy." -dependencies = [ - "Mako", - "SQLAlchemy>=1.3.0", - "typing-extensions>=4", -] -files = [ - {file = "alembic-1.12.0-py3-none-any.whl", hash = "sha256:03226222f1cf943deee6c85d9464261a6c710cd19b4fe867a3ad1f25afda610f"}, - {file = "alembic-1.12.0.tar.gz", hash = "sha256:8e7645c32e4f200675e69f0745415335eb59a3663f5feb487abfa0b30c45888b"}, -] +content_hash = "sha256:a21cddc4d65e0a7fe73dbb45b768c4df300795ea87c5305831b767c1370661a3" [[package]] name = "annotated-types" @@ -708,19 +693,6 @@ files = [ {file = "loguru-0.7.2.tar.gz", hash = "sha256:e671a53522515f34fd406340ee968cb9ecafbc4b36c679da03c18fd8d0bd51ac"}, ] -[[package]] -name = "mako" -version = "1.2.4" -requires_python = ">=3.7" -summary = "A super-fast templating language that borrows the best ideas from the existing templating languages." -dependencies = [ - "MarkupSafe>=0.9.2", -] -files = [ - {file = "Mako-1.2.4-py3-none-any.whl", hash = "sha256:c97c79c018b9165ac9922ae4f32da095ffd3c4e6872b45eded42926deea46818"}, - {file = "Mako-1.2.4.tar.gz", hash = "sha256:d60a3903dc3bb01a18ad6a89cdbe2e4eadc69c0bc8ef1e3773ba53d44c3f7a34"}, -] - [[package]] name = "markdown" version = "3.4.4" diff --git a/src/backend/pyproject.toml b/src/backend/pyproject.toml index befb60dd8a..a9852a9106 100644 --- a/src/backend/pyproject.toml +++ b/src/backend/pyproject.toml @@ -34,7 +34,6 @@ dependencies = [ "SQLAlchemy-Utils==0.41.1", "psycopg2==2.9.7", "geoalchemy2==0.14.1", - "alembic>=1.12.0", "geojson==3.0.1", "shapely==2.0.1", "pyxform==1.12.1",