-
Notifications
You must be signed in to change notification settings - Fork 0
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 #13 from DostEducation/feature/2-user-details-base…
…d-tables Added user details based tables
- Loading branch information
Showing
8 changed files
with
280 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from api import db | ||
from api.mixins import TimestampMixin | ||
|
||
|
||
class UserActivities(TimestampMixin, db.Model): | ||
|
||
__tablename__ = "user_activities" | ||
id = db.Column(db.Integer, primary_key=True) | ||
user_id = db.Column(db.Integer, db.ForeignKey("users.id")) | ||
user_phone = db.Column(db.Integer, nullable=False, index=True) | ||
user_flow_id = db.Column(db.Integer, db.ForeignKey("user_flows.id")) | ||
activity = db.Column(db.String(500)) | ||
is_started = db.Column(db.Boolean, default=False, nullable=False) | ||
started_on = db.Column(db.DateTime) | ||
is_succeeded = db.Column(db.Boolean, default=False, nullable=False) | ||
succeeded_on = db.Column(db.DateTime) | ||
is_completed = db.Column(db.Boolean, default=False, nullable=False) | ||
completed_on = db.Column(db.DateTime) |
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,12 @@ | ||
from api import db | ||
from api.mixins import TimestampMixin | ||
|
||
|
||
class UserAttributes(TimestampMixin, db.Model): | ||
|
||
__tablename__ = "user_attributes" | ||
id = db.Column(db.Integer, primary_key=True) | ||
user_id = db.Column(db.Integer, db.ForeignKey("users.id")) | ||
user_phone = db.Column(db.Integer, nullable=False, index=True) | ||
field_name = db.Column(db.String(255)) | ||
field_value = db.Column(db.String(255)) |
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,17 @@ | ||
from api import db | ||
from api.mixins import TimestampMixin | ||
|
||
|
||
class UserFlows(TimestampMixin, db.Model): | ||
|
||
__tablename__ = "user_flows" | ||
id = db.Column(db.Integer, primary_key=True) | ||
user_id = db.Column(db.Integer, db.ForeignKey("users.id")) | ||
user_phone = db.Column(db.Integer, nullable=False, index=True) | ||
flow_uuid = db.Column(db.String(255)) | ||
flow_name = db.Column(db.String(255)) | ||
flow_type = db.Column(db.String(255)) | ||
flow_run_status = db.Column(db.String(255)) | ||
flow_start_time = db.Column(db.DateTime) | ||
flow_end_time = db.Column(db.DateTime) | ||
is_active = db.Column(db.Boolean, default=False, nullable=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,13 @@ | ||
from api import db | ||
from api.mixins import TimestampMixin | ||
|
||
|
||
class UserIndicatorResponses(TimestampMixin, db.Model): | ||
|
||
__tablename__ = "user_indicator_responses" | ||
id = db.Column(db.Integer, primary_key=True) | ||
user_id = db.Column(db.Integer, db.ForeignKey("users.id")) | ||
user_phone = db.Column(db.Integer, nullable=False, index=True) | ||
user_flow_id = db.Column(db.Integer, db.ForeignKey("user_flows.id")) | ||
indicator_question = db.Column(db.String(255)) | ||
indicator_question_response = db.Column(db.String(255)) |
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,12 @@ | ||
from api import db | ||
from api.mixins import TimestampMixin | ||
|
||
|
||
class Users(TimestampMixin, db.Model): | ||
|
||
__tablename__ = "users" | ||
id = db.Column(db.Integer, primary_key=True) | ||
glific_user_id = db.Column(db.Integer) | ||
phone = db.Column(db.Integer, nullable=False, index=True) | ||
name = db.Column(db.String(255)) | ||
location = db.Column(db.String(255)) |
198 changes: 198 additions & 0 deletions
198
migrations/versions/648c8318ea08_user_detail_based_tables.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,198 @@ | ||
"""User detail based tables. | ||
Revision ID: 648c8318ea08 | ||
Revises: 70bea50174bf | ||
Create Date: 2024-04-24 10:13:43.211473 | ||
""" | ||
|
||
import sqlalchemy as sa | ||
from alembic import op | ||
from sqlalchemy.dialects import postgresql | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "648c8318ea08" | ||
down_revision = "70bea50174bf" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.create_table( | ||
"users", | ||
sa.Column("id", sa.Integer(), nullable=False), | ||
sa.Column("glific_user_id", sa.Integer(), nullable=True), | ||
sa.Column("phone", sa.Integer(), nullable=False), | ||
sa.Column("name", sa.String(length=255), nullable=True), | ||
sa.Column("location", sa.String(length=255), nullable=True), | ||
sa.Column("created_on", sa.DateTime(), nullable=False), | ||
sa.Column("updated_on", sa.DateTime(), nullable=False), | ||
sa.PrimaryKeyConstraint("id"), | ||
) | ||
with op.batch_alter_table("users", schema=None) as batch_op: | ||
batch_op.create_index( | ||
batch_op.f("ix_users_phone"), ["phone"], unique=False | ||
) | ||
|
||
op.create_table( | ||
"user_attributes", | ||
sa.Column("id", sa.Integer(), nullable=False), | ||
sa.Column("user_id", sa.Integer(), nullable=True), | ||
sa.Column("user_phone", sa.Integer(), nullable=False), | ||
sa.Column("field_name", sa.String(length=255), nullable=True), | ||
sa.Column("field_value", sa.String(length=255), nullable=True), | ||
sa.Column("created_on", sa.DateTime(), nullable=False), | ||
sa.Column("updated_on", sa.DateTime(), nullable=False), | ||
sa.ForeignKeyConstraint( | ||
["user_id"], | ||
["users.id"], | ||
), | ||
sa.PrimaryKeyConstraint("id"), | ||
) | ||
with op.batch_alter_table("user_attributes", schema=None) as batch_op: | ||
batch_op.create_index( | ||
batch_op.f("ix_user_attributes_user_phone"), | ||
["user_phone"], | ||
unique=False, | ||
) | ||
|
||
op.create_table( | ||
"user_flows", | ||
sa.Column("id", sa.Integer(), nullable=False), | ||
sa.Column("user_id", sa.Integer(), nullable=True), | ||
sa.Column("user_phone", sa.Integer(), nullable=False), | ||
sa.Column("flow_uuid", sa.String(length=255), nullable=True), | ||
sa.Column("flow_name", sa.String(length=255), nullable=True), | ||
sa.Column("flow_type", sa.String(length=255), nullable=True), | ||
sa.Column("flow_run_status", sa.String(length=255), nullable=True), | ||
sa.Column("flow_start_time", sa.DateTime(), nullable=True), | ||
sa.Column("flow_end_time", sa.DateTime(), nullable=True), | ||
sa.Column("is_active", sa.Boolean(), nullable=False), | ||
sa.Column("created_on", sa.DateTime(), nullable=False), | ||
sa.Column("updated_on", sa.DateTime(), nullable=False), | ||
sa.ForeignKeyConstraint( | ||
["user_id"], | ||
["users.id"], | ||
), | ||
sa.PrimaryKeyConstraint("id"), | ||
) | ||
with op.batch_alter_table("user_flows", schema=None) as batch_op: | ||
batch_op.create_index( | ||
batch_op.f("ix_user_flows_user_phone"), | ||
["user_phone"], | ||
unique=False, | ||
) | ||
|
||
op.create_table( | ||
"user_activities", | ||
sa.Column("id", sa.Integer(), nullable=False), | ||
sa.Column("user_id", sa.Integer(), nullable=True), | ||
sa.Column("user_phone", sa.Integer(), nullable=False), | ||
sa.Column("user_flow_id", sa.Integer(), nullable=True), | ||
sa.Column("activity", sa.String(length=500), nullable=True), | ||
sa.Column("is_started", sa.Boolean(), nullable=False), | ||
sa.Column("started_on", sa.DateTime(), nullable=True), | ||
sa.Column("is_succeeded", sa.Boolean(), nullable=False), | ||
sa.Column("succeeded_on", sa.DateTime(), nullable=True), | ||
sa.Column("is_completed", sa.Boolean(), nullable=False), | ||
sa.Column("completed_on", sa.DateTime(), nullable=True), | ||
sa.Column("created_on", sa.DateTime(), nullable=False), | ||
sa.Column("updated_on", sa.DateTime(), nullable=False), | ||
sa.ForeignKeyConstraint( | ||
["user_flow_id"], | ||
["user_flows.id"], | ||
), | ||
sa.ForeignKeyConstraint( | ||
["user_id"], | ||
["users.id"], | ||
), | ||
sa.PrimaryKeyConstraint("id"), | ||
) | ||
with op.batch_alter_table("user_activities", schema=None) as batch_op: | ||
batch_op.create_index( | ||
batch_op.f("ix_user_activities_user_phone"), | ||
["user_phone"], | ||
unique=False, | ||
) | ||
|
||
op.create_table( | ||
"user_indicator_responses", | ||
sa.Column("id", sa.Integer(), nullable=False), | ||
sa.Column("user_id", sa.Integer(), nullable=True), | ||
sa.Column("user_phone", sa.Integer(), nullable=False), | ||
sa.Column("user_flow_id", sa.Integer(), nullable=True), | ||
sa.Column("indicator_question", sa.String(length=255), nullable=True), | ||
sa.Column( | ||
"indicator_question_response", sa.String(length=255), nullable=True | ||
), | ||
sa.Column("created_on", sa.DateTime(), nullable=False), | ||
sa.Column("updated_on", sa.DateTime(), nullable=False), | ||
sa.ForeignKeyConstraint( | ||
["user_flow_id"], | ||
["user_flows.id"], | ||
), | ||
sa.ForeignKeyConstraint( | ||
["user_id"], | ||
["users.id"], | ||
), | ||
sa.PrimaryKeyConstraint("id"), | ||
) | ||
with op.batch_alter_table( | ||
"user_indicator_responses", schema=None | ||
) as batch_op: | ||
batch_op.create_index( | ||
batch_op.f("ix_user_indicator_responses_user_phone"), | ||
["user_phone"], | ||
unique=False, | ||
) | ||
|
||
with op.batch_alter_table( | ||
"webhook_transaction_log", schema=None | ||
) as batch_op: | ||
batch_op.alter_column( | ||
"created_on", existing_type=postgresql.TIMESTAMP(), nullable=False | ||
) | ||
batch_op.alter_column( | ||
"updated_on", existing_type=postgresql.TIMESTAMP(), nullable=False | ||
) | ||
|
||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
with op.batch_alter_table( | ||
"webhook_transaction_log", schema=None | ||
) as batch_op: | ||
batch_op.alter_column( | ||
"updated_on", existing_type=postgresql.TIMESTAMP(), nullable=True | ||
) | ||
batch_op.alter_column( | ||
"created_on", existing_type=postgresql.TIMESTAMP(), nullable=True | ||
) | ||
|
||
with op.batch_alter_table( | ||
"user_indicator_responses", schema=None | ||
) as batch_op: | ||
batch_op.drop_index( | ||
batch_op.f("ix_user_indicator_responses_user_phone") | ||
) | ||
|
||
op.drop_table("user_indicator_responses") | ||
with op.batch_alter_table("user_activities", schema=None) as batch_op: | ||
batch_op.drop_index(batch_op.f("ix_user_activities_user_phone")) | ||
|
||
op.drop_table("user_activities") | ||
with op.batch_alter_table("user_flows", schema=None) as batch_op: | ||
batch_op.drop_index(batch_op.f("ix_user_flows_user_phone")) | ||
|
||
op.drop_table("user_flows") | ||
with op.batch_alter_table("user_attributes", schema=None) as batch_op: | ||
batch_op.drop_index(batch_op.f("ix_user_attributes_user_phone")) | ||
|
||
op.drop_table("user_attributes") | ||
with op.batch_alter_table("users", schema=None) as batch_op: | ||
batch_op.drop_index(batch_op.f("ix_users_phone")) | ||
|
||
op.drop_table("users") | ||
# ### end Alembic commands ### |