Entity 스펙 스키마
이 페이지는 Fascia의 Entity(비즈니스 객체) 스펙에 대한 전체 JSON Schema를 정의합니다. Entity는 Fascia의 핵심 비즈니스 객체 추상화로, 필드, 관계, 상태 머신(Status Machine), 불변식(Invariant)을 캡슐화합니다. 데이터베이스 저장 모델(테이블, 컬럼, 인덱스)은 Entity 스펙에서 자동으로 도출됩니다.
JSON Schema
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"required": ["name", "version", "description", "fields", "statusMachine"],
"properties": {
"name": {
"type": "string",
"pattern": "^[A-Z][a-zA-Z0-9]*$",
"description": "PascalCase entity name"
},
"version": {
"type": "integer",
"minimum": 1
},
"description": {
"type": "string"
},
"fields": {
"type": "object",
"minProperties": 1,
"additionalProperties": { "$ref": "#/$defs/Field" }
},
"relationships": {
"type": "object",
"additionalProperties": { "$ref": "#/$defs/Relationship" }
},
"statusMachine": { "$ref": "#/$defs/StatusMachine" },
"invariants": {
"type": "array",
"items": { "$ref": "#/$defs/Invariant" }
},
"rowLevelAccess": {
"type": "boolean",
"default": false
},
"ownerField": {
"type": "string"
}
}
}
최상위 속성
| 속성 | 타입 | 필수 | 설명 |
|---|---|---|---|
name | string | 예 | PascalCase Entity 이름 (예: Reservation, PaymentRecord). ^[A-Z][a-zA-Z0-9]*$ 패턴을 따라야 합니다. |
version | integer | 예 | 불변 버전 번호. 1부터 시작하며, 변경 시마다 증가합니다. |
description | string | 예 | Entity의 목적에 대한 사람이 읽을 수 있는 설명입니다. |
fields | object | 예 | Entity에 정의된 사용자 필드입니다. 최소 하나의 필드가 필요합니다. Field 참조. |
relationships | object | 아니오 | 다른 Entity와의 관계를 정의합니다. Relationship 참조. |
statusMachine | object | 예 | 허용된 상태와 전이를 정의하는 상태 머신입니다. StatusMachine 참조. |
invariants | array | 아니오 | 항상 참이어야 하는 비즈니스 규칙입니다. Invariant 참조. |
rowLevelAccess | boolean | 아니오 | true로 설정 시, 관리자가 아닌 사용자는 자신이 소유한 행에만 접근할 수 있습니다. 기본값은 false입니다. |
ownerField | string | 아니오 | 소유자 User Entity를 참조하는 필드 이름입니다. rowLevelAccess가 true일 때 필수입니다. |
정의
Field
fields 객체의 각 항목은 Entity의 타입이 지정된 데이터 속성을 정의합니다.
{
"type": "object",
"required": ["type"],
"properties": {
"type": {
"enum": ["string", "number", "boolean", "date", "datetime", "enum", "uuid", "json", "reference"]
},
"required": { "type": "boolean", "default": false },
"unique": { "type": "boolean", "default": false },
"indexed": { "type": "boolean", "default": false },
"default": {},
"enumValues": {
"type": "array",
"items": { "type": "string" },
"description": "Required when type is 'enum'"
},
"referenceTo": {
"type": "string",
"description": "Target entity name. Required when type is 'reference'."
},
"description": { "type": "string" }
}
}
| 속성 | 타입 | 필수 | 설명 |
|---|---|---|---|
type | enum | 예 | string, number, boolean, date, datetime, enum, uuid, json, reference 중 하나입니다. |
required | boolean | 아니오 | 해당 필드에 값이 반드시 있어야 하는지 여부입니다. 기본값은 false입니다. |
unique | boolean | 아니오 | 유니크 제약 조건 적용 여부입니다. 기본값은 false입니다. |
indexed | boolean | 아니오 | 쿼리 성능을 위한 인덱스 적용 여부입니다. 기본값은 false입니다. |
default | any | 아니오 | 생성 시 필드 값이 제공되지 않을 때 적용되는 기본값입니다. |
enumValues | string[] | 조건부 | 허용되는 값 목록입니다. type이 "enum"일 때 필수입니다. |
referenceTo | string | 조건부 | 대상 Entity의 PascalCase 이름입니다. type이 "reference"일 때 필수입니다. |
description | string | 아니오 | 필드에 대한 사람이 읽을 수 있는 설명입니다. |
허용되는 필드 타입
| 타입 | 설명 | 데이터베이스 매핑 |
|---|---|---|
string | 텍스트 데이터 | TEXT 또는 VARCHAR |
number | 숫자 데이터 (정수 또는 소수) | NUMERIC |
boolean | 참/거짓 | BOOLEAN |
date | 시간 없는 날짜 | DATE |
datetime | 시간대가 포함된 날짜와 시간 | TIMESTAMPTZ |
enum | 고정된 문자열 값 집합 중 하나 | CHECK 제약 조건이 있는 TEXT |
uuid | UUID 식별자 | UUID |
json | 임의의 JSON 데이터 | JSONB |
reference | 다른 Entity에 대한 외래 키 | UUID (FK 제약 조건) |
Relationship
Entity 간의 관계를 정의합니다.
{
"type": "object",
"required": ["type", "target"],
"properties": {
"type": { "enum": ["hasOne", "hasMany", "belongsTo", "manyToMany"] },
"target": { "type": "string", "description": "Target entity name" },
"foreignKey": { "type": "string" },
"through": { "type": "string", "description": "Join table name for manyToMany" }
}
}
| 속성 | 타입 | 필수 | 설명 |
|---|---|---|---|
type | enum | 예 | hasOne, hasMany, belongsTo, manyToMany 중 하나입니다. |
target | string | 예 | 관련 Entity의 PascalCase 이름입니다. |
foreignKey | string | 아니오 | 외래 키 컬럼 이름입니다. 생략 시 자동으로 도출됩니다. |
through | string | 아니오 | 조인 테이블 이름입니다. manyToMany 관계에서 필수입니다. |