- signup.html: 수집 목적 안내 카드, 생년월일(선택) 필드, 필수/선택 배지 - app.py: /api/signup에 birthday 처리, get_or_create_user birthday 파라미터 - mileage_schema.sql: users 테이블 birthday 컬럼 추가 - dbsetup.py: 기존 DB 마이그레이션 (ALTER TABLE ADD birthday) - kakao_client.py: scope에 phone_number,birthday,birthyear 추가 - privacy.html: 항목별 수집 목적 테이블, 필수/선택 구분, 9항 신설 - kakao-phone-request.md: 전화번호+생일 스코프 신청 사유 문서 - kakao-channel-integration.md: 채널 API 분석 및 알림톡 로드맵 - kakao-chanell-rest-api.md: 카카오 채널 REST API 원문 참고 문서 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
83 lines
2.8 KiB
SQL
83 lines
2.8 KiB
SQL
-- SQLite 마일리지 데이터베이스 스키마
|
|
-- pharmacy-pos-qr-system/backend/db/mileage_schema.sql
|
|
|
|
-- 1. 사용자 테이블 (카카오 로그인 계정)
|
|
CREATE TABLE IF NOT EXISTS users (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
nickname VARCHAR(100),
|
|
profile_image_url VARCHAR(500),
|
|
email VARCHAR(200),
|
|
is_email_verified BOOLEAN DEFAULT FALSE,
|
|
phone VARCHAR(20),
|
|
birthday VARCHAR(10),
|
|
mileage_balance INTEGER DEFAULT 0,
|
|
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
);
|
|
|
|
-- 2. 외부 로그인 매핑 테이블
|
|
CREATE TABLE IF NOT EXISTS customer_identities (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
user_id INTEGER NOT NULL,
|
|
provider VARCHAR(20) NOT NULL,
|
|
provider_user_id VARCHAR(100) NOT NULL,
|
|
provider_data TEXT,
|
|
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
FOREIGN KEY (user_id) REFERENCES users(id),
|
|
UNIQUE(provider, provider_user_id)
|
|
);
|
|
|
|
CREATE INDEX IF NOT EXISTS idx_identities_user ON customer_identities(user_id);
|
|
|
|
-- 3. 영수증 QR 토큰 테이블
|
|
CREATE TABLE IF NOT EXISTS claim_tokens (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
transaction_id VARCHAR(20) NOT NULL,
|
|
pharmacy_id VARCHAR(20),
|
|
token_hash VARCHAR(64) NOT NULL,
|
|
total_amount INTEGER NOT NULL,
|
|
claimable_points INTEGER NOT NULL,
|
|
expires_at DATETIME NOT NULL,
|
|
claimed_at DATETIME,
|
|
claimed_by_user_id INTEGER,
|
|
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
FOREIGN KEY (claimed_by_user_id) REFERENCES users(id),
|
|
UNIQUE(transaction_id),
|
|
UNIQUE(token_hash)
|
|
);
|
|
|
|
CREATE INDEX IF NOT EXISTS idx_tokens_hash ON claim_tokens(token_hash);
|
|
CREATE INDEX IF NOT EXISTS idx_tokens_expires ON claim_tokens(expires_at);
|
|
|
|
-- 4. 마일리지 원장 테이블
|
|
CREATE TABLE IF NOT EXISTS mileage_ledger (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
user_id INTEGER NOT NULL,
|
|
transaction_id VARCHAR(20),
|
|
points INTEGER NOT NULL,
|
|
balance_after INTEGER NOT NULL,
|
|
reason VARCHAR(50) NOT NULL,
|
|
description TEXT,
|
|
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
FOREIGN KEY (user_id) REFERENCES users(id),
|
|
UNIQUE(transaction_id)
|
|
);
|
|
|
|
CREATE INDEX IF NOT EXISTS idx_ledger_user ON mileage_ledger(user_id);
|
|
CREATE INDEX IF NOT EXISTS idx_ledger_transaction ON mileage_ledger(transaction_id);
|
|
|
|
-- 5. POS 고객 연결 테이블
|
|
CREATE TABLE IF NOT EXISTS pos_customer_links (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
user_id INTEGER NOT NULL,
|
|
pharmacy_id VARCHAR(20),
|
|
cuscode VARCHAR(10),
|
|
customer_name VARCHAR(50),
|
|
linked_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
is_active BOOLEAN DEFAULT TRUE,
|
|
FOREIGN KEY (user_id) REFERENCES users(id),
|
|
UNIQUE(user_id, pharmacy_id)
|
|
);
|
|
|
|
CREATE INDEX IF NOT EXISTS idx_links_cuscode ON pos_customer_links(cuscode);
|