Skip to content

Commit

Permalink
Merge pull request #99 from hngprojects/Muritadhor
Browse files Browse the repository at this point in the history
Updated the database models with new tables
  • Loading branch information
Dev-wonderful authored Jul 20, 2024
2 parents 3820c50 + 48a8f57 commit 0cbe91b
Show file tree
Hide file tree
Showing 22 changed files with 498 additions and 182 deletions.
14 changes: 7 additions & 7 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
PYTHON_ENV=dev
DB_TYPE=postgresql
DB_NAME=dbname
DB_USER=user
DB_PASSWORD=password
DB_HOST=127.0.0.1
DB_NAME=""
DB_USER=""
DB_PASSWORD=""
DB_HOST=""
DB_PORT=5432
MYSQL_DRIVER=pymysql
DB_URL="postgresql://user:password@127.0.0.1:5432/dbname"
MYSQL_DRIVER=
DB_URL=postgresql://username:password@host:PORT/dbname
SECRET_KEY = ""
ALGORITHM = HS256
ACCESS_TOKEN_EXPIRE_MINUTES = 10
JWT_REFRESH_EXPIRY=5
APP_URL=
APP_URL=
8 changes: 6 additions & 2 deletions alembic/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
from sqlalchemy import pool
from alembic import context
from decouple import config as decouple_config
from api.v1.models.user import User
from api.v1.models.user import User, WaitlistUser
from api.v1.models.org import Organization
from api.v1.models.profile import Profile
from api.v1.models.product import Product
from api.v1.models.base import Base
from api.v1.models.subscription import Subscription
from api.v1.models.blog import Blog
from api.v1.models.job import Job


# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
Expand All @@ -18,7 +22,7 @@
if config.config_file_name is not None:
fileConfig(config.config_file_name)

database_url = decouple_config('DATABASE_URL')
database_url = decouple_config('DB_URL')

# Set the SQLAlchemy URL dynamically
config.set_main_option('sqlalchemy.url', database_url)
Expand Down
41 changes: 41 additions & 0 deletions alembic/versions/05f17b6961cc_added_blogs_table.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""added blogs table
Revision ID: 05f17b6961cc
Revises: 43c2111ee2c0
Create Date: 2024-07-19 23:25:19.980417
"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision: str = '05f17b6961cc'
down_revision: Union[str, None] = '43c2111ee2c0'
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('blogs',
sa.Column('id', sa.UUID(), nullable=False),
sa.Column('author_id', sa.UUID(), nullable=False),
sa.Column('title', sa.String(length=100), nullable=False),
sa.Column('content', sa.Text(), nullable=True),
sa.Column('image_url', sa.String(length=100), nullable=True),
sa.Column('tags', postgresql.ARRAY(sa.String(length=20)), nullable=True),
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
sa.ForeignKeyConstraint(['author_id'], ['users.id'], ),
sa.PrimaryKeyConstraint('id')
)
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('blogs')
# ### end Alembic commands ###
43 changes: 43 additions & 0 deletions alembic/versions/17be96741cf5_added_jobs_table.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"""added jobs table
Revision ID: 17be96741cf5
Revises: c22e5c00f9c9
Create Date: 2024-07-20 00:52:49.465976
"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = '17be96741cf5'
down_revision: Union[str, None] = 'c22e5c00f9c9'
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('jobs',
sa.Column('id', sa.UUID(), nullable=False),
sa.Column('user_id', sa.UUID(), nullable=False),
sa.Column('title', sa.String(length=255), nullable=False),
sa.Column('description', sa.Text(), nullable=False),
sa.Column('location', sa.String(length=255), nullable=True),
sa.Column('salary', sa.Numeric(precision=10, scale=2), nullable=True),
sa.Column('job_type', sa.String(length=50), nullable=True),
sa.Column('company_name', sa.String(length=255), nullable=True),
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
sa.PrimaryKeyConstraint('id')
)
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('jobs')
# ### end Alembic commands ###
41 changes: 41 additions & 0 deletions alembic/versions/43c2111ee2c0_added_subscription_table.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""added subscription table
Revision ID: 43c2111ee2c0
Revises: 61f79886b26a
Create Date: 2024-07-19 23:01:29.197196
"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = '43c2111ee2c0'
down_revision: Union[str, None] = '61f79886b26a'
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('subscriptions',
sa.Column('id', sa.UUID(), nullable=False),
sa.Column('user_id', sa.UUID(), nullable=False),
sa.Column('plan', sa.String(length=50), nullable=False),
sa.Column('is_active', sa.Boolean(), nullable=True),
sa.Column('start_date', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
sa.Column('end_date', sa.DateTime(timezone=True), nullable=True),
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
sa.PrimaryKeyConstraint('id')
)
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('subscriptions')
# ### end Alembic commands ###
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""initial migration
"""Initial migration
Revision ID: 5a2dc9cc9735
Revision ID: 61f79886b26a
Revises:
Create Date: 2024-07-19 00:08:59.055052
Create Date: 2024-07-19 21:55:31.151038
"""
from typing import Sequence, Union
Expand All @@ -12,7 +12,7 @@


# revision identifiers, used by Alembic.
revision: str = '5a2dc9cc9735'
revision: str = '61f79886b26a'
down_revision: Union[str, None] = None
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
Expand All @@ -24,8 +24,8 @@ def upgrade() -> None:
sa.Column('id', sa.UUID(), nullable=False),
sa.Column('name', sa.String(length=50), nullable=False),
sa.Column('description', sa.Text(), nullable=True),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=True),
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('now()'), nullable=True),
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('name')
)
Expand All @@ -34,7 +34,8 @@ def upgrade() -> None:
sa.Column('name', sa.String(), nullable=False),
sa.Column('description', sa.Text(), nullable=True),
sa.Column('price', sa.Numeric(), nullable=False),
sa.Column('created_at', sa.DateTime(), nullable=False),
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
sa.PrimaryKeyConstraint('id')
)
op.create_table('users',
Expand All @@ -44,8 +45,8 @@ def upgrade() -> None:
sa.Column('password', sa.String(length=255), nullable=False),
sa.Column('first_name', sa.String(length=50), nullable=True),
sa.Column('last_name', sa.String(length=50), nullable=True),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=True),
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('now()'), nullable=True),
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('email'),
sa.UniqueConstraint('username')
Expand All @@ -56,10 +57,11 @@ def upgrade() -> None:
sa.Column('bio', sa.Text(), nullable=True),
sa.Column('phone_number', sa.String(length=50), nullable=True),
sa.Column('avatar_url', sa.String(length=100), nullable=True),
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
sa.PrimaryKeyConstraint('id')
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('user_id')
)
op.create_table('user_organization',
sa.Column('user_id', sa.UUID(), nullable=False),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""updated profile user columns
"""added is_active field to users
Revision ID: 9c01926f167f
Revises: e36c5525f3b6
Create Date: 2024-07-19 06:56:07.545775
Revision ID: 6a60cb2e3102
Revises: 17be96741cf5
Create Date: 2024-07-20 01:06:54.780108
"""
from typing import Sequence, Union
Expand All @@ -12,19 +12,19 @@


# revision identifiers, used by Alembic.
revision: str = '9c01926f167f'
down_revision: Union[str, None] = 'e36c5525f3b6'
revision: str = '6a60cb2e3102'
down_revision: Union[str, None] = '17be96741cf5'
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! ###
pass
op.add_column('users', sa.Column('is_active', sa.Boolean(), nullable=True))
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
pass
op.drop_column('users', 'is_active')
# ### end Alembic commands ###
30 changes: 0 additions & 30 deletions alembic/versions/ba7a518767c3_initial_migration.py

This file was deleted.

38 changes: 38 additions & 0 deletions alembic/versions/c22e5c00f9c9_added_waitlist_users_table.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""added waitlist users table
Revision ID: c22e5c00f9c9
Revises: 05f17b6961cc
Create Date: 2024-07-19 23:40:34.169213
"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = 'c22e5c00f9c9'
down_revision: Union[str, None] = '05f17b6961cc'
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('waitlist_users',
sa.Column('id', sa.UUID(), nullable=False),
sa.Column('email', sa.String(length=100), nullable=False),
sa.Column('full_name', sa.String(length=100), nullable=False),
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('email')
)
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('waitlist_users')
# ### end Alembic commands ###
Loading

0 comments on commit 0cbe91b

Please sign in to comment.