This repository has been archived by the owner on Dec 3, 2024. It is now read-only.
generated from communitiesuk/funding-service-design-TEMPLATE
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
srh-sloan
committed
Nov 7, 2024
1 parent
d961652
commit 33cd935
Showing
18 changed files
with
462 additions
and
0 deletions.
There are no files selected for viewing
154 changes: 154 additions & 0 deletions
154
db/migrations/versions/~2024_11_07_1351-5f9082c024f1_.py
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,154 @@ | ||
"""Adding application-store model. | ||
Revision ID: 5f9082c024f1 | ||
Revises: eecdd097df78 | ||
Create Date: 2024-11-07 13:51:58.709734 | ||
""" | ||
import sqlalchemy as sa | ||
import sqlalchemy_utils | ||
from alembic import op | ||
from sqlalchemy.dialects import postgresql | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "5f9082c024f1" | ||
down_revision = "eecdd097df78" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.create_table( | ||
"applications", | ||
sa.Column("id", sa.UUID(), nullable=False), | ||
sa.Column("account_id", sa.String(), nullable=False), | ||
sa.Column("fund_id", sa.String(), nullable=False), | ||
sa.Column("round_id", sa.String(), nullable=False), | ||
sa.Column("key", sa.String(), nullable=False), | ||
sa.Column("language", postgresql.ENUM(name="language", create_type=False), nullable=True), | ||
sa.Column("reference", sa.String(), nullable=False), | ||
sa.Column("project_name", sa.String(), nullable=True), | ||
sa.Column("started_at", sa.DateTime(), server_default=sa.text("now()"), nullable=True), | ||
sa.Column( | ||
"status", | ||
postgresql.ENUM("NOT_STARTED", "IN_PROGRESS", "SUBMITTED", "COMPLETED", name="application_status"), | ||
nullable=False, | ||
), | ||
sa.Column("date_submitted", sa.DateTime(), nullable=True), | ||
sa.Column("last_edited", sa.DateTime(), server_default=sa.text("now()"), nullable=True), | ||
sa.PrimaryKeyConstraint("id", name=op.f("pk_applications")), | ||
sa.UniqueConstraint("fund_id", "round_id", "key", name="_reference"), | ||
sa.UniqueConstraint("reference", name=op.f("uq_applications_reference")), | ||
) | ||
op.create_table( | ||
"eligibility", | ||
sa.Column("id", sa.UUID(), nullable=False), | ||
sa.Column("form_id", sa.String(), nullable=False), | ||
sa.Column("answers", sa.JSON(), nullable=True), | ||
sa.Column("eligible", sa.Boolean(), nullable=True), | ||
sa.Column("application_id", sa.UUID(), nullable=False), | ||
sa.Column("date_submitted", sa.DateTime(), nullable=True), | ||
sa.ForeignKeyConstraint( | ||
["application_id"], ["applications.id"], name=op.f("fk_eligibility_application_id_applications") | ||
), | ||
sa.PrimaryKeyConstraint("id", name=op.f("pk_eligibility")), | ||
) | ||
op.create_table( | ||
"end_of_application_survey_feedback", | ||
sa.Column("id", sa.Integer(), nullable=False), | ||
sa.Column("application_id", sa.UUID(), nullable=False), | ||
sa.Column("fund_id", sa.String(), nullable=False), | ||
sa.Column("round_id", sa.String(), nullable=False), | ||
sa.Column("page_number", sa.Integer(), nullable=False), | ||
sa.Column("data", sa.JSON(), nullable=True), | ||
sa.Column("date_submitted", sa.DateTime(), server_default=sa.text("now()"), nullable=True), | ||
sa.ForeignKeyConstraint( | ||
["application_id"], | ||
["applications.id"], | ||
name=op.f("fk_end_of_application_survey_feedback_application_id_applications"), | ||
), | ||
sa.PrimaryKeyConstraint("id", name=op.f("pk_end_of_application_survey_feedback")), | ||
sa.UniqueConstraint("application_id", "page_number", name="_unique_application_page"), | ||
) | ||
op.create_table( | ||
"feedback", | ||
sa.Column("id", sa.UUID(), nullable=False), | ||
sa.Column("application_id", sa.UUID(), nullable=False), | ||
sa.Column("fund_id", sa.String(), nullable=False), | ||
sa.Column("round_id", sa.String(), nullable=False), | ||
sa.Column("section_id", sa.String(), nullable=False), | ||
sa.Column("feedback_json", sa.JSON(), nullable=False), | ||
sa.Column( | ||
"status", | ||
sa.Enum("NOT_STARTED", "IN_PROGRESS", "SUBMITTED", "COMPLETED", name="feedback_status"), | ||
nullable=False, | ||
), | ||
sa.Column("date_submitted", sa.DateTime(), server_default=sa.text("now()"), nullable=True), | ||
sa.ForeignKeyConstraint( | ||
["application_id"], ["applications.id"], name=op.f("fk_feedback_application_id_applications") | ||
), | ||
sa.PrimaryKeyConstraint("id", name=op.f("pk_feedback")), | ||
sa.UniqueConstraint("application_id", "section_id", name=op.f("uq_feedback_application_id")), | ||
) | ||
op.create_table( | ||
"forms", | ||
sa.Column("id", sqlalchemy_utils.types.uuid.UUIDType(binary=False), nullable=False), | ||
sa.Column("application_id", sa.UUID(), nullable=False), | ||
sa.Column("json", sa.JSON(), nullable=True), | ||
sa.Column( | ||
"status", | ||
sa.Enum("NOT_STARTED", "IN_PROGRESS", "SUBMITTED", "COMPLETED", name="form_status"), | ||
nullable=False, | ||
), | ||
sa.Column("name", sa.String(), nullable=False), | ||
sa.Column("has_completed", sa.Boolean(), nullable=True), | ||
sa.ForeignKeyConstraint( | ||
["application_id"], ["applications.id"], name=op.f("fk_forms_application_id_applications") | ||
), | ||
sa.PrimaryKeyConstraint("id", name=op.f("pk_forms")), | ||
sa.UniqueConstraint("id", "name", name=op.f("uq_forms_id")), | ||
) | ||
op.create_table( | ||
"research_survey", | ||
sa.Column("id", sa.Integer(), nullable=False), | ||
sa.Column("application_id", sa.UUID(), nullable=False), | ||
sa.Column("fund_id", sa.String(), nullable=False), | ||
sa.Column("round_id", sa.String(), nullable=False), | ||
sa.Column("data", sa.JSON(), nullable=True), | ||
sa.Column("date_submitted", sa.DateTime(), server_default=sa.text("now()"), nullable=True), | ||
sa.ForeignKeyConstraint( | ||
["application_id"], ["applications.id"], name=op.f("fk_research_survey_application_id_applications") | ||
), | ||
sa.PrimaryKeyConstraint("id", name=op.f("pk_research_survey")), | ||
sa.UniqueConstraint("application_id", name=op.f("uq_research_survey_application_id")), | ||
) | ||
with op.batch_alter_table("assessment_records", schema=None) as batch_op: | ||
batch_op.create_index( | ||
"ix_jsonb_blob_nURkuc", [sa.text("(jsonb_blob -> 'nURkuc')")], unique=False, postgresql_using="gin" | ||
) | ||
|
||
with op.batch_alter_table("tags", schema=None) as batch_op: | ||
batch_op.drop_index("value_round_id_unique_idx") | ||
batch_op.create_index("tag_value_round_id_ix", [sa.text("lower(value)"), "round_id"], unique=True) | ||
|
||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
|
||
with op.batch_alter_table("tags", schema=None) as batch_op: | ||
batch_op.drop_index("tag_value_round_id_ix") | ||
batch_op.create_index("value_round_id_unique_idx", [sa.text("lower(value::text)"), "round_id"], unique=True) | ||
|
||
with op.batch_alter_table("assessment_records", schema=None) as batch_op: | ||
batch_op.drop_index("ix_jsonb_blob_nURkuc", postgresql_using="gin") | ||
|
||
op.drop_table("research_survey") | ||
op.drop_table("forms") | ||
op.drop_table("feedback") | ||
op.drop_table("end_of_application_survey_feedback") | ||
op.drop_table("eligibility") | ||
op.drop_table("applications") | ||
# ### end Alembic commands ### |
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 @@ | ||
from .applications import Applications # noqa |
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,63 @@ | ||
import uuid | ||
|
||
from db import db | ||
from db.models.application.enums import Language | ||
from db.models.application.enums import Status | ||
from flask_sqlalchemy.model import DefaultMeta | ||
from sqlalchemy import Column | ||
from sqlalchemy import DateTime | ||
from sqlalchemy.dialects.postgresql import ENUM | ||
from sqlalchemy.dialects.postgresql import UUID | ||
from sqlalchemy.orm import relationship | ||
from sqlalchemy.sql import func | ||
|
||
|
||
BaseModel: DefaultMeta = db.Model | ||
|
||
|
||
class Applications(BaseModel): | ||
id = Column( | ||
"id", | ||
UUID(as_uuid=True), | ||
default=uuid.uuid4, | ||
primary_key=True, | ||
nullable=False, | ||
) | ||
account_id = Column("account_id", db.String(), nullable=False) | ||
fund_id = Column("fund_id", db.String(), nullable=False) | ||
round_id = Column("round_id", db.String(), nullable=False) | ||
key = Column("key", db.String(), nullable=False) | ||
language = Column("language", ENUM(Language), nullable=True) | ||
reference = Column("reference", db.String(), nullable=False, unique=True) | ||
project_name = Column( | ||
"project_name", | ||
db.String(), | ||
nullable=True, | ||
) | ||
started_at = Column("started_at", DateTime(), server_default=func.now()) | ||
status = Column("status", ENUM(Status), default="NOT_STARTED", nullable=False) | ||
date_submitted = Column("date_submitted", DateTime()) | ||
last_edited = Column("last_edited", DateTime(), server_default=func.now()) | ||
forms = relationship("Forms") | ||
feedbacks = relationship("Feedback") | ||
end_of_application_survey = relationship("EndOfApplicationSurveyFeedback") | ||
|
||
__table_args__ = (db.UniqueConstraint("fund_id", "round_id", "key", name="_reference"),) | ||
|
||
def as_dict(self): | ||
date_submitted = self.date_submitted.isoformat() if self.date_submitted else "null" | ||
return { | ||
"id": str(self.id), | ||
"account_id": self.account_id, | ||
"round_id": self.round_id, | ||
"fund_id": self.fund_id, | ||
"language": self.language.name if self.language else "en", | ||
"reference": self.reference, | ||
"project_name": self.project_name or None, | ||
"started_at": self.started_at.isoformat() if self.started_at else None, | ||
"status": self.status.name if self.status else None, | ||
"last_edited": self.last_edited.isoformat() | ||
if self.last_edited | ||
else (self.started_at.isoformat() if self.started_at else None), | ||
"date_submitted": date_submitted, | ||
} |
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,13 @@ | ||
from enum import Enum | ||
|
||
|
||
class Language(Enum): | ||
en = 0 | ||
cy = 1 | ||
|
||
|
||
class Status(Enum): | ||
NOT_STARTED = 0 | ||
IN_PROGRESS = 1 | ||
SUBMITTED = 2 | ||
COMPLETED = 3 |
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 @@ | ||
from .eligibility import * # noqa |
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,39 @@ | ||
import uuid | ||
|
||
from db import db | ||
from db.models.application.applications import Applications | ||
from flask_sqlalchemy.model import DefaultMeta | ||
from sqlalchemy import Column | ||
from sqlalchemy import DateTime | ||
from sqlalchemy.dialects.postgresql import UUID | ||
from sqlalchemy_json import NestedMutableJson | ||
|
||
|
||
BaseModel: DefaultMeta = db.Model | ||
|
||
|
||
class Eligibility(BaseModel): | ||
id = Column( | ||
"id", | ||
UUID(as_uuid=True), | ||
default=uuid.uuid4, | ||
primary_key=True, | ||
nullable=False, | ||
) | ||
form_id = Column("form_id", db.String(), nullable=False) | ||
answers = Column("answers", NestedMutableJson) | ||
eligible = Column("eligible", db.Boolean(), nullable=True) | ||
application_id = db.Column("application_id", db.ForeignKey(Applications.id), nullable=False) | ||
date_submitted = db.Column("date_submitted", DateTime()) | ||
|
||
def as_dict(self): | ||
date_submitted = self.date_submitted.isoformat() if self.date_submitted else "null" | ||
|
||
return { | ||
"id": str(self.id), | ||
"form_id": self.form_id, | ||
"answers": self.answers, | ||
"eligible": self.eligible, | ||
"application_id": self.application_id, | ||
"date_submitted": date_submitted, | ||
} |
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,16 @@ | ||
from uuid import uuid4 | ||
|
||
from db import db | ||
from flask_sqlalchemy.model import DefaultMeta | ||
from sqlalchemy import Column | ||
from sqlalchemy.dialects.postgresql import UUID | ||
from sqlalchemy.sql import func | ||
|
||
|
||
BaseModel: DefaultMeta = db.Model | ||
|
||
|
||
class EligibilityUpdate(BaseModel): | ||
id = Column("id", UUID(as_uuid=True), default=uuid4, primary_key=True) | ||
date_created = Column("date_created", db.DateTime(), server_default=func.now()) | ||
eligible = Column("eligible", db.Boolean()) |
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,2 @@ | ||
from .end_of_application_survey import EndOfApplicationSurveyFeedback # noqa | ||
from .feedback import Feedback # noqa |
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,31 @@ | ||
from db import db | ||
from flask_sqlalchemy.model import DefaultMeta | ||
from sqlalchemy import DateTime | ||
from sqlalchemy.dialects.postgresql import UUID | ||
from sqlalchemy.sql import func | ||
|
||
|
||
BaseModel: DefaultMeta = db.Model | ||
|
||
|
||
class EndOfApplicationSurveyFeedback(BaseModel): | ||
id = db.Column(db.Integer, primary_key=True) | ||
application_id = db.Column(UUID(as_uuid=True), db.ForeignKey("applications.id"), nullable=False) | ||
fund_id = db.Column("fund_id", db.String(), nullable=False) | ||
round_id = db.Column("round_id", db.String(), nullable=False) | ||
page_number = db.Column(db.Integer, nullable=False) | ||
data = db.Column(db.JSON, nullable=True) | ||
date_submitted = db.Column("date_submitted", DateTime(), server_default=func.now()) | ||
|
||
__table_args__ = (db.UniqueConstraint("application_id", "page_number", name="_unique_application_page"),) | ||
|
||
def as_dict(self): | ||
return { | ||
"id": self.id, | ||
"application_id": self.application_id, | ||
"fund_id": self.fund_id, | ||
"round_id": self.round_id, | ||
"page_number": self.page_number, | ||
"data": self.data, | ||
"date_submitted": self.date_submitted, | ||
} |
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,13 @@ | ||
from enum import Enum | ||
|
||
|
||
class Language(Enum): | ||
en = 0 | ||
cy = 1 | ||
|
||
|
||
class Status(Enum): | ||
NOT_STARTED = 0 | ||
IN_PROGRESS = 1 | ||
SUBMITTED = 2 | ||
COMPLETED = 3 |
Oops, something went wrong.