From e7fdc6ba40882dfabdc331eb17cabd743bc3dc7d Mon Sep 17 00:00:00 2001 From: tsugumi-sys Date: Sun, 7 Jul 2024 10:15:35 +0900 Subject: [PATCH] Database: Adding wiki sp500 table --- stocklake/stores/db/models.py | 24 ++++++++- .../c8deb56c7d92_adding_wikisp500_table.py | 51 +++++++++++++++++++ 2 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 stocklake/stores/db_migrations/versions/c8deb56c7d92_adding_wikisp500_table.py diff --git a/stocklake/stores/db/models.py b/stocklake/stores/db/models.py index 7eef759..76e9dd3 100644 --- a/stocklake/stores/db/models.py +++ b/stocklake/stores/db/models.py @@ -29,9 +29,13 @@ class NasdaqApiData(Base): class PolygonFinancialsData(Base): __tablename__ = "polygonapi_financials_data" - # financials data - # - balance sheet + id = Column(Integer, primary_key=True) + created_at = Column(DateTime(timezone=True), default=func.now()) + updated_at = Column( + DateTime(timezone=True), default=func.now(), onupdate=func.now() + ) + equity_attributable_to_noncontrolling_interest = Column(Float, nullable=True) liabilities = Column(Float, nullable=True) equity_attributable_to_parent = Column(Float, nullable=True) @@ -97,3 +101,19 @@ class PolygonFinancialsData(Base): fiscal_year = Column(Integer, nullable=True) source_filing_url = Column(String, nullable=True) source_filing_file_url = Column(String, nullable=True) + + +class WikiSP500Data(Base): + __tablename__ = "wiki_sp500" + + id = Column(Integer, primary_key=True) + created_at = Column(DateTime(timezone=True), default=func.now()) + updated_at = Column( + DateTime(timezone=True), default=func.now(), onupdate=func.now() + ) + + symbol = Column(String) + company = Column(String) + sector = Column(String, nullable=True) + industry = Column(String, nullable=True) + headquarters = Column(String, nullable=True) diff --git a/stocklake/stores/db_migrations/versions/c8deb56c7d92_adding_wikisp500_table.py b/stocklake/stores/db_migrations/versions/c8deb56c7d92_adding_wikisp500_table.py new file mode 100644 index 0000000..178e3e3 --- /dev/null +++ b/stocklake/stores/db_migrations/versions/c8deb56c7d92_adding_wikisp500_table.py @@ -0,0 +1,51 @@ +"""adding wikisp500 table + +Revision ID: c8deb56c7d92 +Revises: 84fb754ea7f6 +Create Date: 2024-07-07 10:15:09.525907 + +""" + +from typing import Sequence, Union + +import sqlalchemy as sa +from alembic import op + +# revision identifiers, used by Alembic. +revision: str = "c8deb56c7d92" +down_revision: Union[str, None] = "84fb754ea7f6" +branch_labels: Union[str, Sequence[str], None] = None +depends_on: Union[str, Sequence[str], None] = None + + +def upgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.create_table( + "wiki_sp500", + sa.Column("id", sa.Integer(), nullable=False), + sa.Column("created_at", sa.DateTime(timezone=True), nullable=True), + sa.Column("updated_at", sa.DateTime(timezone=True), nullable=True), + sa.Column("symbol", sa.String(), nullable=True), + sa.Column("company", sa.String(), nullable=True), + sa.Column("sector", sa.String(), nullable=True), + sa.Column("industry", sa.String(), nullable=True), + sa.Column("headquarters", sa.String(), nullable=True), + sa.PrimaryKeyConstraint("id"), + ) + op.add_column( + "polygonapi_financials_data", + sa.Column("created_at", sa.DateTime(timezone=True), nullable=True), + ) + op.add_column( + "polygonapi_financials_data", + sa.Column("updated_at", sa.DateTime(timezone=True), nullable=True), + ) + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.drop_column("polygonapi_financials_data", "updated_at") + op.drop_column("polygonapi_financials_data", "created_at") + op.drop_table("wiki_sp500") + # ### end Alembic commands ###