Skip to content

Commit

Permalink
Reset db migrations (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
andersy005 authored Dec 6, 2023
1 parent fac995e commit 4114e18
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""reset migrations and add new fields to project
Revision ID: 8ed0e389ff06
Revision ID: 895a2d11e837
Revises:
Create Date: 2023-11-16 15:08:07.974455
Create Date: 2023-12-06 04:34:16.583574
"""
import sqlalchemy as sa
Expand All @@ -11,7 +11,7 @@
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision = '8ed0e389ff06'
revision = '895a2d11e837'
down_revision = None
branch_labels = None
depends_on = None
Expand All @@ -21,11 +21,11 @@ def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.create_table(
'clip',
sa.Column('tags', postgresql.ARRAY(sa.String()), nullable=True),
sa.Column('date', sa.Date(), nullable=False),
sa.Column('title', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.Column('url', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.Column('source', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.Column('tags', postgresql.ARRAY(sa.String()), nullable=True),
sa.Column('notes', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.Column('is_waybacked', sa.Boolean(), nullable=True),
sa.Column('type', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
Expand All @@ -51,18 +51,18 @@ def upgrade() -> None:
)
op.create_table(
'project',
sa.Column('protocol', postgresql.ARRAY(sa.String()), nullable=True),
sa.Column('category', postgresql.ARRAY(sa.String()), nullable=True),
sa.Column('retired', sa.BigInteger(), nullable=True),
sa.Column('issued', sa.BigInteger(), nullable=True),
sa.Column('project_id', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column('name', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.Column('registry', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column('proponent', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.Column('protocol', postgresql.ARRAY(sa.String()), nullable=True),
sa.Column('category', postgresql.ARRAY(sa.String()), nullable=True),
sa.Column('status', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.Column('country', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.Column('listed_at', sa.Date(), nullable=True),
sa.Column('is_compliance', sa.Boolean(), nullable=True),
sa.Column('retired', sa.BigInteger(), nullable=True),
sa.Column('issued', sa.BigInteger(), nullable=True),
sa.Column('first_issuance_at', sa.Date(), nullable=True),
sa.Column('first_retirement_at', sa.Date(), nullable=True),
sa.Column('project_url', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
Expand Down
26 changes: 15 additions & 11 deletions offsets_db_api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,21 @@ class ProjectBase(SQLModel):
)
status: str | None
country: str | None
listed_at: datetime.datetime | None = Field(description='Date project was listed')
listed_at: datetime.date | None = pydantic.Field(
description='Date project was listed', strict=False
)
is_compliance: bool | None = Field(description='Whether project is compliance project')
retired: int | None = Field(
description='Total of retired credits', default=0, sa_column=Column(BigInteger())
)
issued: int | None = Field(
description='Total of issued credits', default=0, sa_column=Column(BigInteger())
)
first_issuance_at: datetime.datetime | None = Field(
description='Date of first issuance of credits'
first_issuance_at: datetime.date | None = pydantic.Field(
description='Date of first issuance of credits', strict=False
)
first_retirement_at: datetime.datetime | None = Field(
description='Date of first retirement of credits'
first_retirement_at: datetime.date | None = pydantic.Field(
description='Date of first retirement of credits', strict=False
)
project_url: str | None = Field(description='URL to project details')

Expand All @@ -64,7 +66,7 @@ class Project(ProjectBase, table=True):


class ClipBase(SQLModel):
date: datetime.datetime = Field(description='Date the clip was published')
date: datetime.date = pydantic.Field(description='Date the clip was published', strict=False)
title: str | None = Field(description='Title of the clip')
url: str | None = Field(description='URL to the clip')
source: str | None = Field(description='Source of the clip')
Expand Down Expand Up @@ -112,7 +114,9 @@ class ProjectWithClips(ProjectBase):
class CreditBase(SQLModel):
quantity: int = Field(description='Number of credits', sa_column=Column(BigInteger()))
vintage: int | None = Field(description='Vintage year of credits')
transaction_date: datetime.datetime | None = Field(description='Date of transaction')
transaction_date: datetime.date | None = pydantic.Field(
description='Date of transaction', strict=False
)
transaction_type: str | None = Field(description='Type of transaction')


Expand Down Expand Up @@ -144,8 +148,8 @@ class PaginatedCredits(pydantic.BaseModel):


class BinnedValues(pydantic.BaseModel):
start: datetime.datetime | None
end: datetime.datetime | None
start: datetime.date | None = pydantic.Field(description='Start date of bin', strict=False)
end: datetime.date | None = pydantic.Field(description='End date of bin', strict=False)
category: str | None
value: int | None

Expand All @@ -156,8 +160,8 @@ class PaginatedBinnedValues(pydantic.BaseModel):


class ProjectCreditTotals(pydantic.BaseModel):
start: datetime.datetime | None
end: datetime.datetime | None
start: datetime.date | None = pydantic.Field(description='Start date of bin', strict=False)
end: datetime.date | None = pydantic.Field(description='End date of bin', strict=False)
value: int | None


Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ dependencies = [
"s3fs>=2023",
"sqlmodel==0.0.14",
"pandera>=0.17",
"offsets-db-data>=2023.11.11",
"offsets-db-data>=2023.11.12",
]

[project.urls]
Expand Down

0 comments on commit 4114e18

Please sign in to comment.