-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #77 from dataforgoodfr/rs/add-amp-table-in-alembic
Add amp table in alembic
- Loading branch information
Showing
7 changed files
with
1,365 additions
and
1,459 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import logging | ||
import os | ||
from pathlib import Path | ||
|
||
import pandas as pd | ||
from sqlalchemy import create_engine | ||
|
||
logging.basicConfig() | ||
logging.getLogger("sqlalchemy.engine").setLevel(logging.INFO) | ||
|
||
postgres_user = os.environ.get("POSTGRES_USER") | ||
postgres_password = os.environ.get("POSTGRES_PASSWORD") | ||
postgres_hostname = os.environ.get("POSTGRES_HOSTNAME") | ||
postgres_db = os.environ.get("POSTGRES_DB") | ||
postgres_port = os.environ.get("POSTGRES_PORT") | ||
|
||
# The db url is configured with the db connexion variables declared in the db.yaml file. | ||
db_url = ( | ||
"postgresql://" | ||
+ postgres_user | ||
+ ":" | ||
+ postgres_password | ||
+ "@" | ||
+ postgres_hostname | ||
+ ":" | ||
+ postgres_port | ||
+ "/" | ||
+ postgres_db | ||
) | ||
engine = create_engine(db_url) | ||
df = pd.read_csv( | ||
Path.joinpath(Path.cwd(), "spire_positions_subset_02022024.csv"), | ||
sep="," | ||
) | ||
|
||
df.to_sql("spire_vessel_positions", engine, if_exists="append", index=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
"""create amp table | ||
Revision ID: 961cee5426d6 | ||
Revises: 1fd83d22bd1e | ||
Create Date: 2024-02-11 22:10:19.010986 | ||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
import geoalchemy2 | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = '961cee5426d6' | ||
down_revision = '1fd83d22bd1e' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade() -> None: | ||
op.create_table("mpa_fr_with_mn", | ||
sa.Column("index", sa.Integer, primary_key=True), | ||
sa.Column("wdpaid", sa.Integer), | ||
sa.Column("name", sa.String, nullable=False), | ||
sa.Column("desig_eng", sa.String), | ||
sa.Column("desig_type", sa.String), | ||
sa.Column("iucn_cat", sa.String), | ||
sa.Column("parent_iso", sa.String), | ||
sa.Column("iso3", sa.String), | ||
sa.Column("geometry", geoalchemy2.types.Geometry(geometry_type="GEOMETRY", srid=4326)), | ||
sa.Column("benificiaries", sa.String) | ||
) | ||
|
||
|
||
def downgrade() -> None: | ||
conn = op.get_bind() | ||
inspector = Inspector.from_engine(conn) | ||
sql_tables = inspector.get_table_names() | ||
tables = [ | ||
"mpa_fr_with_mn", | ||
] | ||
for t in tables: | ||
if t in sql_tables: | ||
op.drop_table(t) |
Oops, something went wrong.