create-entity-server 0.7.11 → 0.9.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -14,10 +14,8 @@ fi
14
14
  LANGUAGE=${LANGUAGE:-ko}
15
15
 
16
16
  SERVICE_NAME="entity-server"
17
- RUN_USER="${SUDO_USER:-$(stat -c '%U' "$PROJECT_ROOT")}"
18
- RUN_GROUP="$(id -gn "$RUN_USER" 2>/dev/null || true)"
19
- START_NOW=true
20
- INTERACTIVE=false
17
+ RUN_USER="$(id -un)"
18
+ RUN_GROUP="$(id -gn)"
21
19
  SERVER_CONFIG="$PROJECT_ROOT/configs/server.json"
22
20
  SERVER_BIN="$PROJECT_ROOT/bin/entity-server"
23
21
  if [ ! -f "$SERVER_BIN" ] && [ -f "$PROJECT_ROOT/entity-server" ]; then
@@ -25,8 +23,8 @@ if [ ! -f "$SERVER_BIN" ] && [ -f "$PROJECT_ROOT/entity-server" ]; then
25
23
  fi
26
24
 
27
25
  load_namespace() {
28
- local namespace=""
29
- if [ -f "$SERVER_CONFIG" ]; then
26
+ local namespace="${SERVER_NAMESPACE:-${NAMESPACE:-}}"
27
+ if [ -z "$namespace" ] && [ -f "$SERVER_CONFIG" ]; then
30
28
  namespace=$(sed -n 's/.*"namespace"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' "$SERVER_CONFIG" | head -n 1)
31
29
  fi
32
30
  namespace=$(echo "$namespace" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9_-]/-/g')
@@ -38,89 +36,6 @@ load_namespace() {
38
36
 
39
37
  load_namespace
40
38
 
41
- if [ $# -eq 0 ]; then
42
- INTERACTIVE=true
43
- fi
44
-
45
- for arg in "$@"; do
46
- case "$arg" in
47
- --user=*)
48
- RUN_USER="${arg#*=}"
49
- ;;
50
- --group=*)
51
- RUN_GROUP="${arg#*=}"
52
- ;;
53
- --no-start)
54
- START_NOW=false
55
- ;;
56
- *)
57
- if [ "$LANGUAGE" = "en" ]; then
58
- echo "❌ Unknown option: $arg"
59
- echo " Service name is fixed: $SERVICE_NAME"
60
- else
61
- echo "❌ 알 수 없는 옵션: $arg"
62
- echo " 서비스명은 자동 고정값입니다: $SERVICE_NAME"
63
- fi
64
- exit 1
65
- ;;
66
- esac
67
- done
68
-
69
- if [ "$INTERACTIVE" = true ]; then
70
- if [ "$LANGUAGE" = "en" ]; then
71
- echo "[interactive] systemd service setup"
72
- echo "service name: $SERVICE_NAME"
73
- else
74
- echo "[interactive] systemd 서비스 설정"
75
- echo "서비스명: $SERVICE_NAME"
76
- fi
77
-
78
- read -r -p "Run user [$RUN_USER]: " input
79
- if [ -n "$input" ]; then
80
- RUN_USER="$input"
81
- fi
82
-
83
- if [ -z "$RUN_GROUP" ]; then
84
- RUN_GROUP="$(id -gn "$RUN_USER" 2>/dev/null || true)"
85
- fi
86
- read -r -p "Run group [$RUN_GROUP]: " input
87
- if [ -n "$input" ]; then
88
- RUN_GROUP="$input"
89
- fi
90
-
91
- if [ "$LANGUAGE" = "en" ]; then
92
- read -r -p "Start service now? [Y/n]: " input
93
- else
94
- read -r -p "서비스를 즉시 시작할까요? [Y/n]: " input
95
- fi
96
- input=$(echo "$input" | tr '[:upper:]' '[:lower:]')
97
- if [ "$input" = "n" ] || [ "$input" = "no" ]; then
98
- START_NOW=false
99
- fi
100
- fi
101
-
102
- if [ "$RUN_GROUP" = "" ]; then
103
- RUN_GROUP="$(id -gn "$RUN_USER")"
104
- fi
105
-
106
- if ! id -u "$RUN_USER" >/dev/null 2>&1; then
107
- if [ "$LANGUAGE" = "en" ]; then
108
- echo "❌ User not found: $RUN_USER"
109
- else
110
- echo "❌ 사용자를 찾을 수 없습니다: $RUN_USER"
111
- fi
112
- exit 1
113
- fi
114
-
115
- if ! getent group "$RUN_GROUP" >/dev/null 2>&1; then
116
- if [ "$LANGUAGE" = "en" ]; then
117
- echo "❌ Group not found: $RUN_GROUP"
118
- else
119
- echo "❌ 그룹을 찾을 수 없습니다: $RUN_GROUP"
120
- fi
121
- exit 1
122
- fi
123
-
124
39
  if [ ! -x "$PROJECT_ROOT/scripts/run.sh" ]; then
125
40
  chmod +x "$PROJECT_ROOT/scripts/run.sh"
126
41
  fi
@@ -140,11 +55,7 @@ UNIT_PATH="/etc/systemd/system/${SERVICE_NAME}.service"
140
55
 
141
56
  if [ "$EUID" -ne 0 ]; then
142
57
  if command -v sudo >/dev/null 2>&1; then
143
- SUDO_ARGS=("--user=$RUN_USER" "--group=$RUN_GROUP")
144
- if [ "$START_NOW" = false ]; then
145
- SUDO_ARGS+=("--no-start")
146
- fi
147
- exec sudo "$0" "${SUDO_ARGS[@]}"
58
+ exec sudo "$0"
148
59
  fi
149
60
  if [ "$LANGUAGE" = "en" ]; then
150
61
  echo "❌ This script requires root privileges"
@@ -177,20 +88,18 @@ EOF
177
88
  systemctl daemon-reload
178
89
  systemctl enable "$SERVICE_NAME"
179
90
 
180
- if [ "$START_NOW" = true ]; then
181
- systemctl restart "$SERVICE_NAME"
182
- fi
183
-
184
91
  if [ "$LANGUAGE" = "en" ]; then
185
92
  echo "✅ Service registered: $SERVICE_NAME"
186
93
  echo " Unit: $UNIT_PATH"
187
- echo " Start: sudo systemctl start $SERVICE_NAME"
188
- echo " Stop: sudo systemctl stop $SERVICE_NAME"
189
- echo " Status: sudo systemctl status $SERVICE_NAME"
94
+ echo " User: $RUN_USER"
95
+ echo " Start: ./run.sh start"
96
+ echo " Stop: ./run.sh stop"
97
+ echo " Status: ./run.sh status"
190
98
  else
191
99
  echo "✅ 서비스 등록 완료: $SERVICE_NAME"
192
100
  echo " Unit: $UNIT_PATH"
193
- echo " 시작: sudo systemctl start $SERVICE_NAME"
194
- echo " 중지: sudo systemctl stop $SERVICE_NAME"
195
- echo " 상태: sudo systemctl status $SERVICE_NAME"
101
+ echo " User: $RUN_USER"
102
+ echo " 시작: ./run.sh start"
103
+ echo " 중지: ./run.sh stop"
104
+ echo " 상태: ./run.sh status"
196
105
  fi
@@ -19,8 +19,8 @@ CONFIRMED=false
19
19
  SERVER_CONFIG="$PROJECT_ROOT/configs/server.json"
20
20
 
21
21
  load_namespace() {
22
- local namespace=""
23
- if [ -f "$SERVER_CONFIG" ]; then
22
+ local namespace="${SERVER_NAMESPACE:-${NAMESPACE:-}}"
23
+ if [ -z "$namespace" ] && [ -f "$SERVER_CONFIG" ]; then
24
24
  namespace=$(sed -n 's/.*"namespace"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' "$SERVER_CONFIG" | head -n 1)
25
25
  fi
26
26
  namespace=$(echo "$namespace" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9_-]/-/g')
@@ -1,145 +1,145 @@
1
- # Sync entity index schema
2
-
3
- param(
4
- [string]$Target = "",
5
- [switch]$Apply,
6
- [switch]$WithData
7
- )
8
-
9
- $ProjectRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot)
10
- Set-Location $ProjectRoot
11
-
12
- # Load language from .env
13
- $Language = "ko"
14
- if (Test-Path ".env") {
15
- $EnvLine = Get-Content ".env" | Where-Object { $_ -match '^LANGUAGE=' }
16
- if ($EnvLine) { $Language = $EnvLine -replace '^LANGUAGE=', '' }
17
- }
18
-
19
- # Show usage if no arguments
20
- if (-not $Target) {
21
- if ($Language -eq "en") {
22
- Write-Host "Sync Entity Index Schema"
23
- Write-Host "========================"
24
- Write-Host ""
25
- Write-Host "Synchronize index table schema with entity configuration."
26
- Write-Host ""
27
- Write-Host "Usage: .\sync.ps1 <EntityName>|-All [-Apply] [-WithData]"
28
- Write-Host ""
29
- Write-Host "Arguments:"
30
- Write-Host " EntityName Name of the entity to sync (required)"
31
- Write-Host " -All Sync all entities in entities/"
32
- Write-Host ""
33
- Write-Host "Options:"
34
- Write-Host " -Apply Apply changes to database (default: dry-run)"
35
- Write-Host " -WithData Sync schema and backfill index rows from existing data"
36
- Write-Host ""
37
- Write-Host "Examples:"
38
- Write-Host " .\sync.ps1 user # Preview changes for user entity"
39
- Write-Host " .\sync.ps1 user -Apply # Apply changes for user entity"
40
- Write-Host " .\sync.ps1 user -Apply -WithData # Apply + backfill"
41
- Write-Host " .\sync.ps1 -All # Preview for all entities"
42
- Write-Host " .\sync.ps1 -All -Apply # Apply for all entities"
43
- Write-Host " .\sync.ps1 license -Apply # Sync license entity schema"
44
- } else {
45
- Write-Host "엔티티 인덱스 스키마 동기화"
46
- Write-Host "======================="
47
- Write-Host ""
48
- Write-Host "엔티티 설정과 인덱스 테이블 스키마를 동기화합니다."
49
- Write-Host ""
50
- Write-Host "사용법: .\sync.ps1 <엔티티명>|-All [-Apply] [-WithData]"
51
- Write-Host ""
52
- Write-Host "인자:"
53
- Write-Host " 엔티티명 동기화할 엔티티 이름 (필수)"
54
- Write-Host " -All entities/ 내 전체 엔티티 동기화"
55
- Write-Host ""
56
- Write-Host "옵션:"
57
- Write-Host " -Apply 데이터베이스에 변경사항 적용 (기본값: 미리보기)"
58
- Write-Host " -WithData 스키마 동기화 + 기존 데이터 인덱스 백필"
59
- Write-Host ""
60
- Write-Host "예제:"
61
- Write-Host " .\sync.ps1 user # user 엔티티 변경사항 미리보기"
62
- Write-Host " .\sync.ps1 user -Apply # user 엔티티 변경사항 적용"
63
- Write-Host " .\sync.ps1 user -Apply -WithData # 적용 + 기존 데이터 백필"
64
- Write-Host " .\sync.ps1 -All # 전체 엔티티 미리보기"
65
- Write-Host " .\sync.ps1 -All -Apply # 전체 엔티티 적용"
66
- Write-Host " .\sync.ps1 license -Apply # license 엔티티 스키마 동기화"
67
- }
68
- exit 0
69
- }
70
-
71
- # Validate --with-data requires --apply
72
- if ($WithData -and -not $Apply) {
73
- if ($Language -eq "en") {
74
- Write-Host "❌ -WithData requires -Apply"
75
- } else {
76
- Write-Host "❌ -WithData 는 -Apply 와 함께 사용해야 합니다"
77
- }
78
- exit 1
79
- }
80
-
81
- # Require prebuilt CLI binary
82
- $CliBin = Join-Path $ProjectRoot "entity-cli.exe"
83
- if (-not (Test-Path $CliBin)) {
84
- if ($Language -eq "en") {
85
- Write-Host "❌ entity-cli.exe not found"
86
- } else {
87
- Write-Host "❌ entity-cli.exe 파일이 없습니다"
88
- }
89
- exit 1
90
- }
91
-
92
- function Invoke-SyncEntity {
93
- param([string]$EntityName)
94
- $Args = @("sync-index", "--entity=$EntityName")
95
- if ($Apply) { $Args += "--apply" }
96
- if ($WithData) { $Args += "--with-data" }
97
- Write-Host "[sync] $EntityName"
98
- & $CliBin @Args
99
- return $LASTEXITCODE -eq 0
100
- }
101
-
102
- if ($Target -eq "-All" -or $Target -eq "--all") {
103
- $EntityFiles = Get-ChildItem -Path (Join-Path $ProjectRoot "entities") -Filter "*.json" -Recurse |
104
- Select-Object -ExpandProperty BaseName | Sort-Object -Unique
105
-
106
- if ($EntityFiles.Count -eq 0) {
107
- if ($Language -eq "en") {
108
- Write-Host "❌ No entity config files found in entities/"
109
- } else {
110
- Write-Host "❌ entities/ 에 엔티티 설정 파일이 없습니다"
111
- }
112
- exit 1
113
- }
114
-
115
- $TotalCount = $EntityFiles.Count
116
- $SuccessCount = 0
117
- $FailedCount = 0
118
-
119
- foreach ($Entity in $EntityFiles) {
120
- if (Invoke-SyncEntity $Entity) {
121
- $SuccessCount++
122
- } else {
123
- $FailedCount++
124
- }
125
- }
126
-
127
- $ApplyLabel = if ($Apply) { "apply" } else { "dry-run" }
128
- $ModeLabel = if ($WithData) { "with-data" } else { "index-only" }
129
- Write-Host ""
130
- Write-Host "[summary] target=all mode=$ModeLabel apply=$ApplyLabel total=$TotalCount success=$SuccessCount failed=$FailedCount"
131
-
132
- if ($FailedCount -gt 0) { exit 1 }
133
- } else {
134
- $ok = Invoke-SyncEntity $Target
135
- $ApplyLabel = if ($Apply) { "apply" } else { "dry-run" }
136
- $ModeLabel = if ($WithData) { "with-data" } else { "index-only" }
137
- if ($ok) {
138
- Write-Host ""
139
- Write-Host "[summary] target=$Target mode=$ModeLabel apply=$ApplyLabel total=1 success=1 failed=0"
140
- } else {
141
- Write-Host ""
142
- Write-Host "[summary] target=$Target mode=$ModeLabel apply=$ApplyLabel total=1 success=0 failed=1"
143
- exit 1
144
- }
145
- }
1
+ # Sync entity index schema
2
+
3
+ param(
4
+ [string]$Target = "",
5
+ [switch]$Apply,
6
+ [switch]$WithData
7
+ )
8
+
9
+ $ProjectRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot)
10
+ Set-Location $ProjectRoot
11
+
12
+ # Load language from .env
13
+ $Language = "ko"
14
+ if (Test-Path ".env") {
15
+ $EnvLine = Get-Content ".env" | Where-Object { $_ -match '^LANGUAGE=' }
16
+ if ($EnvLine) { $Language = $EnvLine -replace '^LANGUAGE=', '' }
17
+ }
18
+
19
+ # Show usage if no arguments
20
+ if (-not $Target) {
21
+ if ($Language -eq "en") {
22
+ Write-Host "Sync Entity Index Schema"
23
+ Write-Host "========================"
24
+ Write-Host ""
25
+ Write-Host "Synchronize index table schema with entity configuration."
26
+ Write-Host ""
27
+ Write-Host "Usage: .\sync.ps1 <EntityName>|-All [-Apply] [-WithData]"
28
+ Write-Host ""
29
+ Write-Host "Arguments:"
30
+ Write-Host " EntityName Name of the entity to sync (required)"
31
+ Write-Host " -All Sync all entities in entities/"
32
+ Write-Host ""
33
+ Write-Host "Options:"
34
+ Write-Host " -Apply Apply changes to database (default: dry-run)"
35
+ Write-Host " -WithData Sync schema and backfill index rows from existing data"
36
+ Write-Host ""
37
+ Write-Host "Examples:"
38
+ Write-Host " .\sync.ps1 user # Preview changes for user entity"
39
+ Write-Host " .\sync.ps1 user -Apply # Apply changes for user entity"
40
+ Write-Host " .\sync.ps1 user -Apply -WithData # Apply + backfill"
41
+ Write-Host " .\sync.ps1 -All # Preview for all entities"
42
+ Write-Host " .\sync.ps1 -All -Apply # Apply for all entities"
43
+ Write-Host " .\sync.ps1 license -Apply # Sync license entity schema"
44
+ } else {
45
+ Write-Host "엔티티 인덱스 스키마 동기화"
46
+ Write-Host "======================="
47
+ Write-Host ""
48
+ Write-Host "엔티티 설정과 인덱스 테이블 스키마를 동기화합니다."
49
+ Write-Host ""
50
+ Write-Host "사용법: .\sync.ps1 <엔티티명>|-All [-Apply] [-WithData]"
51
+ Write-Host ""
52
+ Write-Host "인자:"
53
+ Write-Host " 엔티티명 동기화할 엔티티 이름 (필수)"
54
+ Write-Host " -All entities/ 내 전체 엔티티 동기화"
55
+ Write-Host ""
56
+ Write-Host "옵션:"
57
+ Write-Host " -Apply 데이터베이스에 변경사항 적용 (기본값: 미리보기)"
58
+ Write-Host " -WithData 스키마 동기화 + 기존 데이터 인덱스 백필"
59
+ Write-Host ""
60
+ Write-Host "예제:"
61
+ Write-Host " .\sync.ps1 user # user 엔티티 변경사항 미리보기"
62
+ Write-Host " .\sync.ps1 user -Apply # user 엔티티 변경사항 적용"
63
+ Write-Host " .\sync.ps1 user -Apply -WithData # 적용 + 기존 데이터 백필"
64
+ Write-Host " .\sync.ps1 -All # 전체 엔티티 미리보기"
65
+ Write-Host " .\sync.ps1 -All -Apply # 전체 엔티티 적용"
66
+ Write-Host " .\sync.ps1 license -Apply # license 엔티티 스키마 동기화"
67
+ }
68
+ exit 0
69
+ }
70
+
71
+ # Validate --with-data requires --apply
72
+ if ($WithData -and -not $Apply) {
73
+ if ($Language -eq "en") {
74
+ Write-Host "❌ -WithData requires -Apply"
75
+ } else {
76
+ Write-Host "❌ -WithData 는 -Apply 와 함께 사용해야 합니다"
77
+ }
78
+ exit 1
79
+ }
80
+
81
+ # Require prebuilt CLI binary
82
+ $CliBin = Join-Path $ProjectRoot "entity-cli.exe"
83
+ if (-not (Test-Path $CliBin)) {
84
+ if ($Language -eq "en") {
85
+ Write-Host "❌ entity-cli.exe not found"
86
+ } else {
87
+ Write-Host "❌ entity-cli.exe 파일이 없습니다"
88
+ }
89
+ exit 1
90
+ }
91
+
92
+ function Invoke-SyncEntity {
93
+ param([string]$EntityName)
94
+ $Args = @("sync-index", "--entity=$EntityName")
95
+ if ($Apply) { $Args += "--apply" }
96
+ if ($WithData) { $Args += "--with-data" }
97
+ Write-Host "[sync] $EntityName"
98
+ & $CliBin @Args
99
+ return $LASTEXITCODE -eq 0
100
+ }
101
+
102
+ if ($Target -eq "-All" -or $Target -eq "--all") {
103
+ $EntityFiles = Get-ChildItem -Path (Join-Path $ProjectRoot "entities") -Filter "*.json" -Recurse |
104
+ Select-Object -ExpandProperty BaseName | Sort-Object -Unique
105
+
106
+ if ($EntityFiles.Count -eq 0) {
107
+ if ($Language -eq "en") {
108
+ Write-Host "❌ No entity config files found in entities/"
109
+ } else {
110
+ Write-Host "❌ entities/ 에 엔티티 설정 파일이 없습니다"
111
+ }
112
+ exit 1
113
+ }
114
+
115
+ $TotalCount = $EntityFiles.Count
116
+ $SuccessCount = 0
117
+ $FailedCount = 0
118
+
119
+ foreach ($Entity in $EntityFiles) {
120
+ if (Invoke-SyncEntity $Entity) {
121
+ $SuccessCount++
122
+ } else {
123
+ $FailedCount++
124
+ }
125
+ }
126
+
127
+ $ApplyLabel = if ($Apply) { "apply" } else { "dry-run" }
128
+ $ModeLabel = if ($WithData) { "with-data" } else { "index-only" }
129
+ Write-Host ""
130
+ Write-Host "[summary] target=all mode=$ModeLabel apply=$ApplyLabel total=$TotalCount success=$SuccessCount failed=$FailedCount"
131
+
132
+ if ($FailedCount -gt 0) { exit 1 }
133
+ } else {
134
+ $ok = Invoke-SyncEntity $Target
135
+ $ApplyLabel = if ($Apply) { "apply" } else { "dry-run" }
136
+ $ModeLabel = if ($WithData) { "with-data" } else { "index-only" }
137
+ if ($ok) {
138
+ Write-Host ""
139
+ Write-Host "[summary] target=$Target mode=$ModeLabel apply=$ApplyLabel total=1 success=1 failed=0"
140
+ } else {
141
+ Write-Host ""
142
+ Write-Host "[summary] target=$Target mode=$ModeLabel apply=$ApplyLabel total=1 success=0 failed=1"
143
+ exit 1
144
+ }
145
+ }