Compare commits
2 Commits
df8743a80b
...
e6ed427b68
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e6ed427b68 | ||
|
|
b7b97cb99b |
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,6 +1,7 @@
|
||||
node_modules
|
||||
|
||||
# Output
|
||||
.idea
|
||||
.output
|
||||
.vercel
|
||||
.netlify
|
||||
|
||||
263
LOCAL_DATABASE_LOCATION.md
Normal file
263
LOCAL_DATABASE_LOCATION.md
Normal file
@ -0,0 +1,263 @@
|
||||
# 📍 Cloudflare D1 로컬 데이터베이스 파일 위치
|
||||
|
||||
## 🗂️ 데이터베이스 파일 위치
|
||||
|
||||
Cloudflare Workers의 로컬 개발 환경(`pnpm cf:dev`)에서 사용하는 D1 데이터베이스는 다음 위치에 저장됩니다:
|
||||
|
||||
```
|
||||
C:\giteat\dd\.wrangler\state\v3\d1\miniflare-D1DatabaseObject\
|
||||
└── e833abeb83abd38e60de8166ab13bbd4d7a5636dc148a7fd8ec47b7678c87854.sqlite
|
||||
```
|
||||
|
||||
### 전체 경로
|
||||
```
|
||||
프로젝트폴더\.wrangler\state\v3\d1\miniflare-D1DatabaseObject\[해시].sqlite
|
||||
```
|
||||
|
||||
## 📊 현재 데이터베이스 정보
|
||||
|
||||
### 파일 크기
|
||||
- **20,480 bytes** (약 20 KB)
|
||||
|
||||
### 포함된 테이블
|
||||
```
|
||||
┌─────────────────┐
|
||||
│ name │
|
||||
├─────────────────┤
|
||||
│ users │ ← 우리가 생성한 테이블
|
||||
│ sqlite_sequence │ ← SQLite 내부 테이블 (AUTO_INCREMENT 관리)
|
||||
│ _cf_METADATA │ ← Cloudflare 메타데이터
|
||||
└─────────────────┘
|
||||
```
|
||||
|
||||
## 🔍 왜 프로젝트 폴더에서 찾을 수 없나요?
|
||||
|
||||
### 1. 숨김 디렉토리
|
||||
`.wrangler` 디렉토리는 앞에 점(`.`)이 있어서 기본적으로 숨겨진 폴더입니다.
|
||||
|
||||
### 2. Wrangler가 자동 관리
|
||||
`wrangler dev` 실행 시 자동으로 생성되고 관리됩니다.
|
||||
|
||||
### 3. gitignore에 포함
|
||||
일반적으로 `.gitignore`에 포함되어 Git에 커밋되지 않습니다.
|
||||
|
||||
## 📁 전체 .wrangler 구조
|
||||
|
||||
```
|
||||
.wrangler/
|
||||
├── state/
|
||||
│ └── v3/
|
||||
│ ├── d1/ # D1 데이터베이스
|
||||
│ │ └── miniflare-D1DatabaseObject/
|
||||
│ │ └── [해시].sqlite # ← 여기!
|
||||
│ ├── do/ # Durable Objects
|
||||
│ │ └── dd-CounterDurableObject/
|
||||
│ │ ├── [해시].sqlite
|
||||
│ │ ├── [해시].sqlite-shm
|
||||
│ │ └── [해시].sqlite-wal
|
||||
│ ├── cache/ # Cache API
|
||||
│ │ └── miniflare-CacheObject/
|
||||
│ │ └── [해시].sqlite
|
||||
│ └── workflows/ # Workflows (비어있음)
|
||||
└── tmp/ # 임시 파일
|
||||
```
|
||||
|
||||
## 🛠️ 데이터베이스 파일 직접 접근
|
||||
|
||||
### 방법 1: Wrangler CLI 사용 (권장)
|
||||
|
||||
```bash
|
||||
# 테이블 조회
|
||||
pnpm wrangler d1 execute auth-db --local --command="SELECT * FROM users"
|
||||
|
||||
# 스키마 확인
|
||||
pnpm wrangler d1 execute auth-db --local --command="PRAGMA table_info(users)"
|
||||
|
||||
# 모든 테이블 조회
|
||||
pnpm wrangler d1 execute auth-db --local --command="SELECT name FROM sqlite_master WHERE type='table'"
|
||||
```
|
||||
|
||||
### 방법 2: SQLite CLI 도구 사용
|
||||
|
||||
```bash
|
||||
# SQLite CLI가 설치되어 있다면
|
||||
sqlite3 .wrangler\state\v3\d1\miniflare-D1DatabaseObject\[해시].sqlite
|
||||
|
||||
# SQLite 프롬프트에서
|
||||
sqlite> .tables
|
||||
sqlite> SELECT * FROM users;
|
||||
sqlite> .schema users
|
||||
```
|
||||
|
||||
### 방법 3: DB Browser for SQLite (GUI)
|
||||
|
||||
1. [DB Browser for SQLite](https://sqlitebrowser.org/) 다운로드
|
||||
2. 파일 열기: `.wrangler\state\v3\d1\miniflare-D1DatabaseObject\[해시].sqlite`
|
||||
3. GUI로 데이터 확인 및 편집
|
||||
|
||||
### 방법 4: Drizzle Studio (권장!)
|
||||
|
||||
```bash
|
||||
pnpm db:studio
|
||||
```
|
||||
|
||||
브라우저에서 자동으로 열리며 데이터베이스를 시각적으로 관리할 수 있습니다.
|
||||
|
||||
## 🔐 해시 파일명의 의미
|
||||
|
||||
파일명인 `e833abeb83abd38e60de8166ab13bbd4d7a5636dc148a7fd8ec47b7678c87854.sqlite`는:
|
||||
|
||||
- **데이터베이스 ID의 해시값**
|
||||
- `wrangler.jsonc`의 `database_id: "local-db"`를 기반으로 생성
|
||||
- 각 데이터베이스마다 고유한 해시를 가짐
|
||||
|
||||
## 📝 데이터베이스 파일 관리
|
||||
|
||||
### 데이터베이스 초기화 (리셋)
|
||||
|
||||
로컬 데이터베이스를 완전히 초기화하고 싶다면:
|
||||
|
||||
```bash
|
||||
# 방법 1: .wrangler 폴더 삭제
|
||||
rmdir /s /q .wrangler
|
||||
|
||||
# 방법 2: D1 폴더만 삭제
|
||||
rmdir /s /q .wrangler\state\v3\d1
|
||||
|
||||
# 그 후 다시 마이그레이션 실행
|
||||
pnpm db:push
|
||||
```
|
||||
|
||||
### 데이터베이스 백업
|
||||
|
||||
```bash
|
||||
# 백업 디렉토리 생성
|
||||
mkdir backups
|
||||
|
||||
# 데이터베이스 파일 복사
|
||||
copy .wrangler\state\v3\d1\miniflare-D1DatabaseObject\*.sqlite backups\local-db-backup.sqlite
|
||||
|
||||
# 또는 SQL 덤프로 백업
|
||||
pnpm wrangler d1 export auth-db --local --output=backups\backup.sql
|
||||
```
|
||||
|
||||
### 데이터베이스 복원
|
||||
|
||||
```bash
|
||||
# SQL 파일로 복원
|
||||
pnpm wrangler d1 execute auth-db --local --file=backups\backup.sql
|
||||
```
|
||||
|
||||
## 🆚 로컬 vs 프로덕션 데이터베이스
|
||||
|
||||
### 로컬 개발 (`--local`)
|
||||
```
|
||||
위치: .wrangler\state\v3\d1\miniflare-D1DatabaseObject\[해시].sqlite
|
||||
접근: pnpm wrangler d1 execute auth-db --local --command="..."
|
||||
```
|
||||
|
||||
### 프로덕션 (`--remote`)
|
||||
```
|
||||
위치: Cloudflare 클라우드 (물리적 접근 불가)
|
||||
접근: pnpm wrangler d1 execute auth-db --remote --command="..."
|
||||
```
|
||||
|
||||
## 🎯 NPM 스크립트로 쉽게 접근
|
||||
|
||||
`package.json`에 이미 추가된 스크립트:
|
||||
|
||||
```json
|
||||
{
|
||||
"scripts": {
|
||||
"db:query": "wrangler d1 execute auth-db --local --command=\"SELECT * FROM users\"",
|
||||
"db:query:remote": "wrangler d1 execute auth-db --remote --command=\"SELECT * FROM users\"",
|
||||
"db:studio": "drizzle-kit studio"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
사용법:
|
||||
```bash
|
||||
# 로컬 사용자 조회
|
||||
pnpm db:query
|
||||
|
||||
# 프로덕션 사용자 조회
|
||||
pnpm db:query:remote
|
||||
|
||||
# Drizzle Studio 실행
|
||||
pnpm db:studio
|
||||
```
|
||||
|
||||
## 🔍 현재 데이터 확인
|
||||
|
||||
로컬 데이터베이스의 현재 사용자를 확인하려면:
|
||||
|
||||
```bash
|
||||
pnpm db:query
|
||||
```
|
||||
|
||||
또는:
|
||||
|
||||
```bash
|
||||
pnpm wrangler d1 execute auth-db --local --command="SELECT id, email, nickname, datetime(created_at, 'unixepoch') as created_at FROM users"
|
||||
```
|
||||
|
||||
## 📊 데이터베이스 통계
|
||||
|
||||
```bash
|
||||
# 사용자 수 확인
|
||||
pnpm wrangler d1 execute auth-db --local --command="SELECT COUNT(*) as user_count FROM users"
|
||||
|
||||
# 데이터베이스 크기 확인
|
||||
pnpm wrangler d1 execute auth-db --local --command="SELECT page_count * page_size as size FROM pragma_page_count(), pragma_page_size()"
|
||||
|
||||
# 마지막 생성된 사용자
|
||||
pnpm wrangler d1 execute auth-db --local --command="SELECT * FROM users ORDER BY created_at DESC LIMIT 1"
|
||||
```
|
||||
|
||||
## 🚨 주의사항
|
||||
|
||||
### 1. 직접 파일 수정 금지
|
||||
SQLite 파일을 직접 편집하는 것은 권장하지 않습니다. 항상 Wrangler CLI나 Drizzle Studio를 사용하세요.
|
||||
|
||||
### 2. 개발 중 데이터 손실 주의
|
||||
`.wrangler` 폴더는 개발용이므로 중요한 데이터를 저장하지 마세요. 프로덕션에는 `--remote`를 사용하세요.
|
||||
|
||||
### 3. Git에 커밋하지 않기
|
||||
`.gitignore`에 `.wrangler` 포함 확인:
|
||||
```gitignore
|
||||
.wrangler/
|
||||
```
|
||||
|
||||
### 4. 팀원과 DB 공유 불가
|
||||
각 개발자는 자신의 로컬 DB를 가집니다. 스키마는 마이그레이션 파일(`drizzle/`)로 공유됩니다.
|
||||
|
||||
## 🎓 정리
|
||||
|
||||
**질문:** `cf:dev`에서 동작할 때 로컬 서버가 바라보고 있는 db 파일은 어디에 있나요?
|
||||
|
||||
**답변:**
|
||||
```
|
||||
C:\giteat\dd\.wrangler\state\v3\d1\miniflare-D1DatabaseObject\
|
||||
└── e833abeb83abd38e60de8166ab13bbd4d7a5636dc148a7fd8ec47b7678c87854.sqlite
|
||||
```
|
||||
|
||||
**쉽게 접근하는 방법:**
|
||||
```bash
|
||||
# Drizzle Studio (GUI)
|
||||
pnpm db:studio
|
||||
|
||||
# CLI로 쿼리
|
||||
pnpm db:query
|
||||
|
||||
# 직접 SQL 실행
|
||||
pnpm wrangler d1 execute auth-db --local --command="SELECT * FROM users"
|
||||
```
|
||||
|
||||
**작동이 정상인 이유:**
|
||||
- Wrangler가 자동으로 `.wrangler` 폴더에 SQLite 파일을 생성하고 관리
|
||||
- `wrangler.jsonc`의 D1 바인딩 설정에 따라 자동으로 연결
|
||||
- 마이그레이션 파일(`drizzle/`)을 실행하여 테이블 생성 완료
|
||||
|
||||
즐거운 개발 되세요! 🚀
|
||||
|
||||
27
MCP_AGENTS.md
Normal file
27
MCP_AGENTS.md
Normal file
@ -0,0 +1,27 @@
|
||||
You are able to use the Svelte MCP server, Cloudflare Documentation MCP server where you have access to comprehensive Svelte 5 and SvelteKit documentation and cloudflare documentation Here's how to use the available tools effectively:
|
||||
|
||||
## Available MCP Tools:
|
||||
|
||||
### 1. cloudflare Documentation server (cloudflare)
|
||||
Get up to date reference information on Cloudflare
|
||||
사용자의 요청이 cloudflare 와 관련이 있을때 이것을 통해 cloudflare 공식문서의 최신자료를 참고하여 작업을 진행함.
|
||||
|
||||
### 2. list-sections (svelte)
|
||||
|
||||
Use this FIRST to discover all available documentation sections. Returns a structured list with titles, use_cases, and paths.
|
||||
When asked about Svelte or SvelteKit topics, ALWAYS use this tool at the start of the chat to find relevant sections.
|
||||
|
||||
### 3. get-documentation (svelte)
|
||||
|
||||
Retrieves full documentation content for specific sections. Accepts single or multiple sections.
|
||||
After calling the list-sections tool, you MUST analyze the returned documentation sections (especially the use_cases field) and then use the get-documentation tool to fetch ALL documentation sections that are relevant for the user's task.
|
||||
|
||||
### 4. svelte-autofixer (svelte)
|
||||
|
||||
Analyzes Svelte code and returns issues and suggestions.
|
||||
You MUST use this tool whenever writing Svelte code before sending it to the user. Keep calling it until no issues or suggestions are returned.
|
||||
|
||||
### 5. playground-link (svelte)
|
||||
|
||||
Generates a Svelte Playground link with the provided code.
|
||||
After completing the code, ask the user if they want a playground link. Only call this tool after user confirmation and NEVER if code was written to files in their project.
|
||||
9
drizzle/0000_omniscient_lady_mastermind.sql
Normal file
9
drizzle/0000_omniscient_lady_mastermind.sql
Normal file
@ -0,0 +1,9 @@
|
||||
CREATE TABLE `users` (
|
||||
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
`email` text NOT NULL,
|
||||
`password_hash` text NOT NULL,
|
||||
`nickname` text NOT NULL,
|
||||
`created_at` integer DEFAULT (strftime('%s', 'now')) NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX `users_email_unique` ON `users` (`email`);
|
||||
72
drizzle/meta/0000_snapshot.json
Normal file
72
drizzle/meta/0000_snapshot.json
Normal file
@ -0,0 +1,72 @@
|
||||
{
|
||||
"version": "6",
|
||||
"dialect": "sqlite",
|
||||
"id": "83c12a3c-ec11-4135-b526-261771d6ede4",
|
||||
"prevId": "00000000-0000-0000-0000-000000000000",
|
||||
"tables": {
|
||||
"users": {
|
||||
"name": "users",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "integer",
|
||||
"primaryKey": true,
|
||||
"notNull": true,
|
||||
"autoincrement": true
|
||||
},
|
||||
"email": {
|
||||
"name": "email",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"password_hash": {
|
||||
"name": "password_hash",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"nickname": {
|
||||
"name": "nickname",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"created_at": {
|
||||
"name": "created_at",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": "(strftime('%s', 'now'))"
|
||||
}
|
||||
},
|
||||
"indexes": {
|
||||
"users_email_unique": {
|
||||
"name": "users_email_unique",
|
||||
"columns": [
|
||||
"email"
|
||||
],
|
||||
"isUnique": true
|
||||
}
|
||||
},
|
||||
"foreignKeys": {},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {},
|
||||
"checkConstraints": {}
|
||||
}
|
||||
},
|
||||
"views": {},
|
||||
"enums": {},
|
||||
"_meta": {
|
||||
"schemas": {},
|
||||
"tables": {},
|
||||
"columns": {}
|
||||
},
|
||||
"internal": {
|
||||
"indexes": {}
|
||||
}
|
||||
}
|
||||
13
drizzle/meta/_journal.json
Normal file
13
drizzle/meta/_journal.json
Normal file
@ -0,0 +1,13 @@
|
||||
{
|
||||
"version": "7",
|
||||
"dialect": "sqlite",
|
||||
"entries": [
|
||||
{
|
||||
"idx": 0,
|
||||
"version": "6",
|
||||
"when": 1763435039243,
|
||||
"tag": "0000_omniscient_lady_mastermind",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
0
src/lib/server/db-old.ts
Normal file
0
src/lib/server/db-old.ts
Normal file
Loading…
x
Reference in New Issue
Block a user