From 92219f8c387f593897010eb3764e59d4d8fd4394 Mon Sep 17 00:00:00 2001 From: yesinkim Date: Sun, 14 Jul 2024 17:18:58 +0900 Subject: [PATCH 1/5] feat: initialize apply schema MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 모집 초안 데이터 스키마 작업 --- app/models/apply/__init__.py | 4 +++ app/models/apply/academy.py | 25 +++++++++++++++++++ app/models/apply/form.py | 47 ++++++++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+) create mode 100644 app/models/apply/__init__.py create mode 100644 app/models/apply/academy.py create mode 100644 app/models/apply/form.py diff --git a/app/models/apply/__init__.py b/app/models/apply/__init__.py new file mode 100644 index 0000000..244ac54 --- /dev/null +++ b/app/models/apply/__init__.py @@ -0,0 +1,4 @@ +from .academy import Academy, Period +from .form import ApplicationForm, Builder, Learner + +__all__ = ["Academy", "Period", "ApplicationForm", "Builder", "Learner"] \ No newline at end of file diff --git a/app/models/apply/academy.py b/app/models/apply/academy.py new file mode 100644 index 0000000..53ae82c --- /dev/null +++ b/app/models/apply/academy.py @@ -0,0 +1,25 @@ +from sqlalchemy import Integer, String, ForeignKey +from sqlalchemy.orm import mapped_column, relationship + +from models.base import Base + +class Period(Base): + __tablename__ = "period" + + id = mapped_column(Integer, primary_key=True) + start = mapped_column(Integer, nullable=True) + end = mapped_column(Integer, nullable=True) + leaner_open = mapped_column(Integer, nullable=True) + leaner_close = mapped_column(Integer, nullable=True) + + +class Academy(Base): + __tablename__ = "academy" + + id = mapped_column(Integer, primary_key=True, nullable=False, comment="아카데미ID") + user_id = mapped_column(Integer, ForeignKey('user.id'), nullable=False, comment="빌더유저ID") + period_id = mapped_column(Integer, ForeignKey('period.id'), nullable=False, comment="기수ID") + academy_name = mapped_column(String, nullable=False, comment="아카데미 이름") + description = mapped_column(String, nullable=True, comment="아카데미 설명") + + # user = relationship("User", back_populates="academie") diff --git a/app/models/apply/form.py b/app/models/apply/form.py new file mode 100644 index 0000000..31af47b --- /dev/null +++ b/app/models/apply/form.py @@ -0,0 +1,47 @@ +from sqlalchemy import JSON, Boolean, DateTime, ForeignKey, Integer, func +from sqlalchemy.orm import mapped_column + +from models.base import Base + + +class ApplicationForm(Base): + __tablename__ = "application_form" + + id = mapped_column(Integer, primary_key=True, comment="신청양식ID") + form_content = mapped_column(JSON, nullable=False, comment="신청양식 내용") + form_type = mapped_column( + Integer, nullable=False, comment="신청양식 구분 (1: builder, 2: learner)" + ) + created_at = mapped_column( + DateTime(timezone=True), server_default=func.now(), comment="입력 날짜" + ) + updated_at = mapped_column( + DateTime(timezone=True), onupdate=func.now(), comment="수정 날짜" + ) + + +class Builder(Base): + __tablename__ = "builder" + + id = mapped_column(Integer, primary_key=True, comment="빌더아카데미ID") + user_id = mapped_column( + Integer, ForeignKey("user.user_id"), nullable=False, comment="빌더유저ID" + ) + form_content = mapped_column(JSON, nullable=False, comment="신청양식 내용") + is_selected = mapped_column(Boolean, nullable=False, comment="빌더 선정 여부") + + +class Learner(Base): + __tablename__ = "learner" + + id = mapped_column(Integer, primary_key=True, comment="러너아카데미ID") + user_id = mapped_column( + Integer, ForeignKey("user.user_id"), nullable=False, comment="러너유저ID" + ) + form_content = mapped_column(JSON, nullable=False, comment="신청양식 내용") + is_selected = mapped_column( + Boolean, nullable=False, comment="러너 선정 여부", default=False + ) + is_completed = mapped_column( + Boolean, nullable=False, comment="수료 여부", default=False + ) From 687322951039c8c5f5384748bebc43cee0950ab1 Mon Sep 17 00:00:00 2001 From: yesinkim Date: Sun, 14 Jul 2024 21:30:27 +0900 Subject: [PATCH 2/5] feat: rename application table MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 제출된 폼 저장하는 테이블을 buider, learner에서 builder_application, learner_application으로 변경 - 외래키 참조할 컬럼 오류 수정(user.id -> user.user_id) --- app/models/apply/__init__.py | 4 ++-- app/models/apply/academy.py | 6 +++--- app/models/apply/form.py | 11 ++++++----- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/app/models/apply/__init__.py b/app/models/apply/__init__.py index 244ac54..8bd5847 100644 --- a/app/models/apply/__init__.py +++ b/app/models/apply/__init__.py @@ -1,4 +1,4 @@ from .academy import Academy, Period -from .form import ApplicationForm, Builder, Learner +from .form import ApplicationForm, BuilderApplication, LearnerApplication -__all__ = ["Academy", "Period", "ApplicationForm", "Builder", "Learner"] \ No newline at end of file +__all__ = ["Academy", "Period", "ApplicationForm", "BuilderApplication", "LearnerApplication"] \ No newline at end of file diff --git a/app/models/apply/academy.py b/app/models/apply/academy.py index 53ae82c..a26e96b 100644 --- a/app/models/apply/academy.py +++ b/app/models/apply/academy.py @@ -17,9 +17,9 @@ class Academy(Base): __tablename__ = "academy" id = mapped_column(Integer, primary_key=True, nullable=False, comment="아카데미ID") - user_id = mapped_column(Integer, ForeignKey('user.id'), nullable=False, comment="빌더유저ID") + user_id = mapped_column(Integer, ForeignKey('user.user_id'), nullable=False, comment="빌더유저ID") period_id = mapped_column(Integer, ForeignKey('period.id'), nullable=False, comment="기수ID") - academy_name = mapped_column(String, nullable=False, comment="아카데미 이름") - description = mapped_column(String, nullable=True, comment="아카데미 설명") + academy_name = mapped_column(String(100), nullable=False, comment="아카데미 이름") + description = mapped_column(String(255), nullable=True, comment="아카데미 설명") # user = relationship("User", back_populates="academie") diff --git a/app/models/apply/form.py b/app/models/apply/form.py index 31af47b..4022bde 100644 --- a/app/models/apply/form.py +++ b/app/models/apply/form.py @@ -1,4 +1,5 @@ -from sqlalchemy import JSON, Boolean, DateTime, ForeignKey, Integer, func +from core.db import AsyncSession +from sqlalchemy import JSON, Boolean, DateTime, ForeignKey, Integer, desc, func, select from sqlalchemy.orm import mapped_column from models.base import Base @@ -20,8 +21,8 @@ class ApplicationForm(Base): ) -class Builder(Base): - __tablename__ = "builder" +class BuilderApplication(Base): + __tablename__ = "builder_application" id = mapped_column(Integer, primary_key=True, comment="빌더아카데미ID") user_id = mapped_column( @@ -31,8 +32,8 @@ class Builder(Base): is_selected = mapped_column(Boolean, nullable=False, comment="빌더 선정 여부") -class Learner(Base): - __tablename__ = "learner" +class LearnerApplication(Base): + __tablename__ = "learner_application" id = mapped_column(Integer, primary_key=True, comment="러너아카데미ID") user_id = mapped_column( From a6bc69b6f2d5b53687035130c668e036961f5725 Mon Sep 17 00:00:00 2001 From: yesinkim Date: Sun, 14 Jul 2024 21:50:25 +0900 Subject: [PATCH 3/5] feat: add comment to Period Table MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - period table에 comment 추가 - 날짜컬럼을 모두 Int로 변경 --- app/models/apply/academy.py | 10 +++++----- app/models/apply/form.py | 8 ++------ 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/app/models/apply/academy.py b/app/models/apply/academy.py index a26e96b..b2290f8 100644 --- a/app/models/apply/academy.py +++ b/app/models/apply/academy.py @@ -6,11 +6,11 @@ class Period(Base): __tablename__ = "period" - id = mapped_column(Integer, primary_key=True) - start = mapped_column(Integer, nullable=True) - end = mapped_column(Integer, nullable=True) - leaner_open = mapped_column(Integer, nullable=True) - leaner_close = mapped_column(Integer, nullable=True) + id = mapped_column(Integer, primary_key=True, comment="기수ID") + start = mapped_column(Integer, nullable=True, comment="기수 시작일") + end = mapped_column(Integer, nullable=True, comment="기수 종료일") + leaner_open = mapped_column(Integer, nullable=True, comment="러너모집 시작일") + leaner_close = mapped_column(Integer, nullable=True, comment="러너모집 종료일") class Academy(Base): diff --git a/app/models/apply/form.py b/app/models/apply/form.py index 4022bde..6ce25cc 100644 --- a/app/models/apply/form.py +++ b/app/models/apply/form.py @@ -13,12 +13,8 @@ class ApplicationForm(Base): form_type = mapped_column( Integer, nullable=False, comment="신청양식 구분 (1: builder, 2: learner)" ) - created_at = mapped_column( - DateTime(timezone=True), server_default=func.now(), comment="입력 날짜" - ) - updated_at = mapped_column( - DateTime(timezone=True), onupdate=func.now(), comment="수정 날짜" - ) + created_at = mapped_column(Integer, comment="입력 날짜") + updated_at = mapped_column(Integer, comment="수정 날짜") class BuilderApplication(Base): From a62c2d01989afe1a19233d7632501282a6099234 Mon Sep 17 00:00:00 2001 From: yesinkim Date: Sun, 21 Jul 2024 10:40:15 +0900 Subject: [PATCH 4/5] =?UTF-8?q?feat:=20table=20=EA=B5=AC=EC=A1=B0=20?= =?UTF-8?q?=EB=B0=8F=20=EC=9D=B4=EB=A6=84=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - builder, leaner application으로 분리되던 테이블을 application으로 통합 - applicationform이라는 모호한 이름을 form_repository로 변경해 모호성 제거 - learneracademy라는 러너와 아카데미를 연결하는 테이블 생성 --- app/models/apply/__init__.py | 6 +++--- app/models/apply/academy.py | 11 ++++++++++- app/models/apply/form.py | 35 +++++++++++------------------------ 3 files changed, 24 insertions(+), 28 deletions(-) diff --git a/app/models/apply/__init__.py b/app/models/apply/__init__.py index 8bd5847..5969410 100644 --- a/app/models/apply/__init__.py +++ b/app/models/apply/__init__.py @@ -1,4 +1,4 @@ -from .academy import Academy, Period -from .form import ApplicationForm, BuilderApplication, LearnerApplication +from .academy import Academy, Period, LearnerAcademy +from .form import FormRepository, Application -__all__ = ["Academy", "Period", "ApplicationForm", "BuilderApplication", "LearnerApplication"] \ No newline at end of file +__all__ = ["Academy", "Period", "LearnerAcademy", "FormRepository", "Application"] \ No newline at end of file diff --git a/app/models/apply/academy.py b/app/models/apply/academy.py index b2290f8..6da3fc0 100644 --- a/app/models/apply/academy.py +++ b/app/models/apply/academy.py @@ -1,4 +1,4 @@ -from sqlalchemy import Integer, String, ForeignKey +from sqlalchemy import Boolean, Integer, String, ForeignKey from sqlalchemy.orm import mapped_column, relationship from models.base import Base @@ -19,7 +19,16 @@ class Academy(Base): id = mapped_column(Integer, primary_key=True, nullable=False, comment="아카데미ID") user_id = mapped_column(Integer, ForeignKey('user.user_id'), nullable=False, comment="빌더유저ID") period_id = mapped_column(Integer, ForeignKey('period.id'), nullable=False, comment="기수ID") + application_id = mapped_column(Integer, ForeignKey('application.id'), nullable=False, comment="신청서ID") academy_name = mapped_column(String(100), nullable=False, comment="아카데미 이름") description = mapped_column(String(255), nullable=True, comment="아카데미 설명") # user = relationship("User", back_populates="academie") + +class LearnerAcademy(Base): + __tablename__ = "learner_academy" + + id = mapped_column(Integer, primary_key=True, nullable=False, comment="러너아카데미ID") + user_id = mapped_column(Integer, ForeignKey("user.user_id"), comment="러너유저ID") + academy_id = mapped_column(Integer, ForeignKey("academy.id"), nullable=False, comment="아카데미ID") + is_completed = mapped_column(Boolean, nullable=False, default=False, comment="수료여부") diff --git a/app/models/apply/form.py b/app/models/apply/form.py index 6ce25cc..7923117 100644 --- a/app/models/apply/form.py +++ b/app/models/apply/form.py @@ -5,40 +5,27 @@ from models.base import Base -class ApplicationForm(Base): - __tablename__ = "application_form" +class FormRepository(Base): + __tablename__ = "form_repository" id = mapped_column(Integer, primary_key=True, comment="신청양식ID") - form_content = mapped_column(JSON, nullable=False, comment="신청양식 내용") form_type = mapped_column( Integer, nullable=False, comment="신청양식 구분 (1: builder, 2: learner)" ) - created_at = mapped_column(Integer, comment="입력 날짜") + form_content = mapped_column(JSON, nullable=False, comment="신청양식 내용") + created_at = mapped_column(Integer, nullable=False, comment="입력 날짜") updated_at = mapped_column(Integer, comment="수정 날짜") -class BuilderApplication(Base): - __tablename__ = "builder_application" +class Application(Base): + __tablename__ = "application" - id = mapped_column(Integer, primary_key=True, comment="빌더아카데미ID") + id = mapped_column(Integer, primary_key=True, comment="신청서ID") user_id = mapped_column( - Integer, ForeignKey("user.user_id"), nullable=False, comment="빌더유저ID" + Integer, ForeignKey("user.user_id"), nullable=False, comment="유저ID" ) - form_content = mapped_column(JSON, nullable=False, comment="신청양식 내용") - is_selected = mapped_column(Boolean, nullable=False, comment="빌더 선정 여부") - - -class LearnerApplication(Base): - __tablename__ = "learner_application" - - id = mapped_column(Integer, primary_key=True, comment="러너아카데미ID") - user_id = mapped_column( - Integer, ForeignKey("user.user_id"), nullable=False, comment="러너유저ID" + form_type = mapped_column( + Integer, nullable=False, comment="신청양식 구분 (1: builder, 2: learner)" ) form_content = mapped_column(JSON, nullable=False, comment="신청양식 내용") - is_selected = mapped_column( - Boolean, nullable=False, comment="러너 선정 여부", default=False - ) - is_completed = mapped_column( - Boolean, nullable=False, comment="수료 여부", default=False - ) + is_selected = mapped_column(Boolean, nullable=False, comment="선정 여부", default=False) \ No newline at end of file From 31d6fc282684831ad416c8464a8568686ce4b9dd Mon Sep 17 00:00:00 2001 From: yesinkim Date: Sun, 21 Jul 2024 10:42:06 +0900 Subject: [PATCH 5/5] style: apply ruff --- app/models/apply/__init__.py | 6 +++--- app/models/apply/academy.py | 10 ++++++---- app/models/apply/form.py | 14 ++++---------- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/app/models/apply/__init__.py b/app/models/apply/__init__.py index 5969410..116af0d 100644 --- a/app/models/apply/__init__.py +++ b/app/models/apply/__init__.py @@ -1,4 +1,4 @@ -from .academy import Academy, Period, LearnerAcademy -from .form import FormRepository, Application +from .academy import Academy, LearnerAcademy, Period +from .form import Application, FormRepository -__all__ = ["Academy", "Period", "LearnerAcademy", "FormRepository", "Application"] \ No newline at end of file +__all__ = ["Academy", "Period", "LearnerAcademy", "FormRepository", "Application"] diff --git a/app/models/apply/academy.py b/app/models/apply/academy.py index 6da3fc0..e212a25 100644 --- a/app/models/apply/academy.py +++ b/app/models/apply/academy.py @@ -1,8 +1,9 @@ -from sqlalchemy import Boolean, Integer, String, ForeignKey +from sqlalchemy import Boolean, ForeignKey, Integer, String from sqlalchemy.orm import mapped_column, relationship from models.base import Base + class Period(Base): __tablename__ = "period" @@ -17,14 +18,15 @@ class Academy(Base): __tablename__ = "academy" id = mapped_column(Integer, primary_key=True, nullable=False, comment="아카데미ID") - user_id = mapped_column(Integer, ForeignKey('user.user_id'), nullable=False, comment="빌더유저ID") - period_id = mapped_column(Integer, ForeignKey('period.id'), nullable=False, comment="기수ID") - application_id = mapped_column(Integer, ForeignKey('application.id'), nullable=False, comment="신청서ID") + user_id = mapped_column(Integer, ForeignKey("user.user_id"), nullable=False, comment="빌더유저ID") + period_id = mapped_column(Integer, ForeignKey("period.id"), nullable=False, comment="기수ID") + application_id = mapped_column(Integer, ForeignKey("application.id"), nullable=False, comment="신청서ID") academy_name = mapped_column(String(100), nullable=False, comment="아카데미 이름") description = mapped_column(String(255), nullable=True, comment="아카데미 설명") # user = relationship("User", back_populates="academie") + class LearnerAcademy(Base): __tablename__ = "learner_academy" diff --git a/app/models/apply/form.py b/app/models/apply/form.py index 7923117..a5ab199 100644 --- a/app/models/apply/form.py +++ b/app/models/apply/form.py @@ -9,9 +9,7 @@ class FormRepository(Base): __tablename__ = "form_repository" id = mapped_column(Integer, primary_key=True, comment="신청양식ID") - form_type = mapped_column( - Integer, nullable=False, comment="신청양식 구분 (1: builder, 2: learner)" - ) + form_type = mapped_column(Integer, nullable=False, comment="신청양식 구분 (1: builder, 2: learner)") form_content = mapped_column(JSON, nullable=False, comment="신청양식 내용") created_at = mapped_column(Integer, nullable=False, comment="입력 날짜") updated_at = mapped_column(Integer, comment="수정 날짜") @@ -21,11 +19,7 @@ class Application(Base): __tablename__ = "application" id = mapped_column(Integer, primary_key=True, comment="신청서ID") - user_id = mapped_column( - Integer, ForeignKey("user.user_id"), nullable=False, comment="유저ID" - ) - form_type = mapped_column( - Integer, nullable=False, comment="신청양식 구분 (1: builder, 2: learner)" - ) + user_id = mapped_column(Integer, ForeignKey("user.user_id"), nullable=False, comment="유저ID") + form_type = mapped_column(Integer, nullable=False, comment="신청양식 구분 (1: builder, 2: learner)") form_content = mapped_column(JSON, nullable=False, comment="신청양식 내용") - is_selected = mapped_column(Boolean, nullable=False, comment="선정 여부", default=False) \ No newline at end of file + is_selected = mapped_column(Boolean, nullable=False, comment="선정 여부", default=False)