문서 목차
이 페이지에서목차

database-design

Serverpod의 데이터 저장 구조를 설계할 때 사용합니다. 모델별 테이블, 데이터 관계와 조회에 필요한 인덱스를 정합니다.

한마디로#

모델별 테이블, 데이터 관계와 조회에 필요한 인덱스를 정합니다.

무엇을·언제#

  • 새로운 데이터 저장 공간(테이블)을 만들 때 구조를 잡아 줍니다.
  • 서로 다른 데이터를 어떻게 연결할지(예: 사용자와 주문 연결) 정리해 줍니다.
  • 데이터 구조를 바꾸거나 새로 적용해야 할 때(마이그레이션) 도와줍니다.
  • 데이터를 더 빠르게 찾도록 검색 성능을 개선해야 할 때 작동합니다.

핵심 용어#

용어쉬운 설명
테이블(table)데이터를 줄과 칸으로 정리한 표, 엑셀 시트와 비슷합니다
관계(relation)서로 다른 표를 연결하는 고리 (예: 고객과 주문 연결)
인덱스(index)책의 색인처럼 원하는 데이터를 빨리 찾게 해 주는 표시
마이그레이션(migration)데이터 구조를 바꾸고 그 변경을 실제로 반영하는 과정
쿼리(query)데이터베이스에 "이런 정보 줘"라고 요청하는 질문
PostgreSQLServerpod가 기본으로 쓰는 데이터 저장 프로그램

Triggers#

  • When designing new database tables
  • When defining relations between tables
  • When creating or applying migrations
  • When query optimization is needed

Actions#

  1. Define models and tables in Serverpod protocol YAML
    • Configure field types, nullable, and default values
    • Declare database mapping with the table keyword
    • Define indexes
  2. Set up relations between tables
    • Define 1:1, 1:N, N:M relationships
    • Use the relation keyword
    • Configure foreign keys and referential integrity
  3. Manage migrations
    • Run the serverpod create-migration command
    • Review and modify migration files
    • Establish rollback strategies
  4. Implement query patterns
    • Use Serverpod's type-safe query builder
    • Handle transactions
    • Implement pagination

Output#

  • Protocol YAML model definitions (with table mapping)
  • Migration SQL files
  • Query code for Repository implementations
  • Index and performance optimization suggestions

Notes#

  • Serverpod uses PostgreSQL as its default database
  • Model definitions are managed in protocol/*.yaml, and serverpod generate auto-generates Dart code and SQL
  • In Clean Architecture, database access is performed only in the Data layer's Repository implementations
  • Database access is through Serverpod's Session.db, which supports type-safe queries
  • For large data processing, use Serverpod's streaming queries and batch processing

검색어를 입력하면 문서를 찾습니다.

↑ ↓ 이동 · Enter 열기Esc 닫기