Skip to content

Commit

Permalink
Merge branch 'main' into jamesbursa/1686-load-legacy-to-staging
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesbursa committed May 2, 2024
2 parents 004f067 + b4b9bf5 commit 23897c6
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 8 deletions.
2 changes: 1 addition & 1 deletion api/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: '3'
services:

grants-db:
image: postgres:14-alpine
image: postgres:15-alpine
container_name: grants-db
command: postgres -c "log_lock_waits=on" -N 1000 -c "fsync=off"
env_file: ./local.env
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"""add unique constraint for summary
Revision ID: 24061ff82646
Revises: 1ddd1d051a99
Create Date: 2024-05-02 10:11:35.832837
"""
from alembic import op

# revision identifiers, used by Alembic.
revision = "24061ff82646"
down_revision = "1ddd1d051a99"
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_unique_constraint(
op.f("opportunity_summary_is_forecast_uniq"),
"opportunity_summary",
["is_forecast", "revision_number", "opportunity_id"],
schema="api",
postgresql_nulls_not_distinct=True,
)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint(
op.f("opportunity_summary_is_forecast_uniq"),
"opportunity_summary",
schema="api",
type_="unique",
)
# ### end Alembic commands ###
2 changes: 1 addition & 1 deletion api/src/db/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def __rich_repr__(self) -> Iterable[tuple[str, Any]]:
class ApiSchemaTable(Base):
__abstract__ = True

__table_args__ = {"schema": Schemas.API}
__table_args__: Any = {"schema": Schemas.API}


@declarative_mixin
Expand Down
12 changes: 11 additions & 1 deletion api/src/db/models/opportunity_models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from datetime import date

from sqlalchemy import BigInteger, ForeignKey
from sqlalchemy import BigInteger, ForeignKey, UniqueConstraint
from sqlalchemy.ext.associationproxy import AssociationProxy, association_proxy
from sqlalchemy.orm import Mapped, mapped_column, relationship

Expand Down Expand Up @@ -86,6 +86,16 @@ def opportunity_status(self) -> OpportunityStatus | None:
class OpportunitySummary(ApiSchemaTable, TimestampMixin):
__tablename__ = "opportunity_summary"

__table_args__ = (
# nulls not distinct makes it so nulls work in the unique constraint
UniqueConstraint(
"is_forecast", "revision_number", "opportunity_id", postgresql_nulls_not_distinct=True
),
# Need to define the table args like this to inherit whatever we set on the super table
# otherwise we end up overwriting things and Alembic remakes the whole table
ApiSchemaTable.__table_args__,
)

opportunity_summary_id: Mapped[int] = mapped_column(BigInteger, primary_key=True)

opportunity_id: Mapped[int] = mapped_column(
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default function RootLayout({ children }: LayoutProps) {
<Layout>{children}</Layout>
</body>
{process.env.NEXT_PUBLIC_ENVIRONMENT === "prod" && (
<GoogleAnalytics gaId={PUBLIC_ENV.GOOGLE_TAG_ID} />
<GoogleAnalytics gaId={PUBLIC_ENV.GOOGLE_ANALYTICS_ID} />
)}
</html>
);
Expand Down
9 changes: 6 additions & 3 deletions frontend/src/constants/environments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
*/
const PUBLIC_ENV_VARS_BY_ENV = {
development: {
GOOGLE_TAG_ID: "GTM-MV57HMHS",
GOOGLE_TAG_MANAGER_ID: "GTM-MV57HMHS",
GOOGLE_ANALYTICS_ID: "G-6MDCC5EZW2",
},
test: {
GOOGLE_TAG_ID: "GTM-MV57HMHS",
GOOGLE_TAG_MANAGER_ID: "GTM-MV57HMHS",
GOOGLE_ANALYTICS_ID: "G-6MDCC5EZW2",
},
production: {
GOOGLE_TAG_ID: "GTM-MV57HMHS",
GOOGLE_TAG_MANAGER_ID: "GTM-MV57HMHS",
GOOGLE_ANALYTICS_ID: "G-6MDCC5EZW2",
},
} as const;

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function MyApp({ Component, pageProps }: AppProps) {
<Layout>
<Component {...pageProps} />
{process.env.NEXT_PUBLIC_ENVIRONMENT === "prod" && (
<GoogleTagManager gtmId={PUBLIC_ENV.GOOGLE_TAG_ID} />
<GoogleTagManager gtmId={PUBLIC_ENV.GOOGLE_TAG_MANAGER_ID} />
)}
</Layout>
</>
Expand Down

0 comments on commit 23897c6

Please sign in to comment.