Skip to content

Commit

Permalink
feat: add migration
Browse files Browse the repository at this point in the history
  • Loading branch information
GareArc committed Dec 21, 2024
1 parent 557fc1f commit 756de62
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 18 deletions.
2 changes: 0 additions & 2 deletions api/libs/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
from flask_restful import fields
from models.account import Account

from api.configs import dify_config


def run(script):
return subprocess.getstatusoutput("source /root/.bashrc && " + script)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""added account_deletion_logs
Revision ID: 582e52119c70
Revises: e1944c35e15e
Create Date: 2024-12-20 21:36:46.856033
"""
from alembic import op
import models as models
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '582e52119c70'
down_revision = 'e1944c35e15e'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('account_deletion_logs',
sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False),
sa.Column('email', sa.String(length=255), nullable=False),
sa.Column('reason', sa.Text(), nullable=True),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False),
sa.PrimaryKeyConstraint('id', name='account_deletion_log_pkey')
)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('account_deletion_logs')
# ### end Alembic commands ###
7 changes: 3 additions & 4 deletions api/services/account_deletion_log_service.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@

from datetime import timedelta

from configs import dify_config
from extensions.ext_database import db

from api.configs import dify_config
from api.libs.helper import get_current_datetime
from api.models.account import AccountDeletionLog
from libs.helper import get_current_datetime
from models.account import AccountDeletionLog


class AccountDeletionLogService:
Expand Down
9 changes: 4 additions & 5 deletions api/services/account_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
TenantAccountRole, TenantStatus)
from models.model import DifySetup
from pydantic import BaseModel
from services.account_deletion_log_service import AccountDeletionLogService
from services.errors.account import (AccountAlreadyInTenantError,
AccountLoginError, AccountNotFoundError,
AccountNotLinkTenantError,
Expand All @@ -37,16 +38,14 @@
from services.errors.workspace import WorkSpaceNotAllowedCreateError
from services.feature_service import FeatureService
from sqlalchemy import func
from tasks.delete_account_task import delete_account_task
from tasks.mail_account_deletion_task import \
send_account_deletion_verification_code
from tasks.mail_email_code_login import send_email_code_login_mail_task
from tasks.mail_invite_member_task import send_invite_member_mail_task
from tasks.mail_reset_password_task import send_reset_password_mail_task
from werkzeug.exceptions import Unauthorized

from api.services.account_deletion_log_service import AccountDeletionLogService
from api.tasks.delete_account_task import delete_account_task
from api.tasks.mail_account_deletion_task import \
send_account_deletion_verification_code


class TokenPair(BaseModel):
access_token: str
Expand Down
13 changes: 6 additions & 7 deletions api/tasks/delete_account_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
import click
from celery import shared_task
from extensions.ext_database import db

from api.models.account import (Account, Tenant, TenantAccountJoin,
TenantAccountJoinRole)
from api.services.account_deletion_log_service import AccountDeletionLogService
from api.services.billing_service import BillingService
from api.tasks.mail_account_deletion_task import (send_deletion_fail_task,
send_deletion_success_task)
from models.account import (Account, Tenant, TenantAccountJoin,
TenantAccountJoinRole)
from services.account_deletion_log_service import AccountDeletionLogService
from services.billing_service import BillingService
from tasks.mail_account_deletion_task import (send_deletion_fail_task,
send_deletion_success_task)

logger = logging.getLogger(__name__)

Expand Down

0 comments on commit 756de62

Please sign in to comment.