@beechcms/api 0.6.0-preview.4 → 0.6.1
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.
- package/assets/dashboard/BeechLogo.svg +18 -18
- package/assets/dashboard/BeechLogoLIght.svg +48 -48
- package/assets/dashboard/assets/chart-CspfxV2U.js +39 -0
- package/assets/dashboard/assets/index-DtDfJyaF.js +644 -0
- package/assets/dashboard/assets/index-Dve7eEqA.css +1 -0
- package/assets/dashboard/assets/{pie-chart-recharts-BMWpjFzf.js → pie-chart-recharts-Bx2IXAjA.js} +1 -1
- package/assets/dashboard/assets/timeseries-chart-recharts-BCWufwI1.js +1 -0
- package/assets/dashboard/beechLogoDark.svg +48 -48
- package/assets/dashboard/index.html +17 -18
- package/assets/dashboard/noResult.svg +42 -42
- package/assets/dashboard/sol.svg +3 -3
- package/assets/dashboard/undraw_enter_nwx3.svg +36 -36
- package/dist/auth/constants.d.ts +5 -5
- package/dist/features/automations/{automations.handler.d.ts → api/automations.handler.d.ts} +1 -1
- package/dist/features/automations/{automation-runner.utils.d.ts → engine/automation-runner.utils.d.ts} +1 -1
- package/dist/features/automations/{action-executors → executors}/edit-field.executor.d.ts +1 -1
- package/dist/features/automations/{action-executors → executors}/index.d.ts +1 -1
- package/dist/features/automations/{action-executors → executors}/send-mail.executor.d.ts +1 -1
- package/dist/features/automations/{action-executors → executors}/set-variable.executor.d.ts +1 -1
- package/dist/features/automations/{action-executors → executors}/webhook.executor.d.ts +1 -1
- package/dist/features/automations/{when-evaluator.d.ts → filters/when-evaluator.d.ts} +1 -1
- package/dist/features/automations/index.d.ts +7 -7
- package/dist/features/content/constants.d.ts +10 -10
- package/dist/features/content/handlers/kanban-move.d.ts +3 -0
- package/dist/features/content/handlers/kanban-position.d.ts +3 -0
- package/dist/features/content/handlers/view-config.d.ts +4 -0
- package/dist/{search.d.ts → features/search/search.d.ts} +1 -1
- package/dist/features/upload/index.d.ts +9 -0
- package/dist/{widget.d.ts → features/widget/widget.d.ts} +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1091 -439
- package/dist/{middleware.d.ts → middleware/auth.middleware.d.ts} +1 -1
- package/dist/middleware/repository.middleware.d.ts +2 -1
- package/dist/public/access-policy.d.ts +1 -1
- package/dist/public/problem-details.d.ts +1 -0
- package/dist/public/public-errors.d.ts +4 -4
- package/dist/rate-limit/cloudflare-rate-limiter.d.ts +4 -1
- package/dist/rate-limit/in-memory-rate-limiter.d.ts +2 -1
- package/dist/shared/{schema-mutator.d1.d.ts → db/migrations/schema-mutator.d1.d.ts} +1 -0
- package/dist/shared/db/repositories/content.repository.d1.d.ts +259 -0
- package/dist/shared/db/repositories/kanban-position.repository.d1.d.ts +9 -0
- package/dist/shared/{seed-layout.repository.d1.d.ts → db/repositories/seed-layout.repository.d1.d.ts} +3 -1
- package/dist/shared/email/email.provider.d.ts +1 -0
- package/dist/{features → shared}/email/email.types.d.ts +1 -16
- package/dist/{features → shared}/email/providers/resend.d.ts +1 -2
- package/dist/{features → shared}/email/providers/smtp.d.ts +1 -2
- package/dist/shared/jobs/queue-consumer.d.ts +9 -0
- package/dist/shared/services/queue/cloudflare-queue-service.d.ts +11 -0
- package/dist/shared/services/queue/in-memory-queue-service.d.ts +16 -0
- package/dist/shared/storage/s3-bucket.d.ts +0 -1
- package/dist/shared/storage/upload.d.ts +7 -0
- package/dist/{media-utils.d.ts → shared/utils/media-utils.d.ts} +4 -2
- package/dist/types.d.ts +93 -2
- package/migrations/0000_v040_base.sql +265 -265
- package/migrations/0029_automations.sql +14 -14
- package/migrations/0030_test_seeds.sql +125 -125
- package/package.json +5 -4
- package/assets/dashboard/assets/chart-BwlCt-IA.js +0 -39
- package/assets/dashboard/assets/index-BcVN-DNy.js +0 -642
- package/assets/dashboard/assets/index-Cf1yRCqG.css +0 -1
- package/assets/dashboard/assets/timeseries-chart-recharts-8_GwAFR0.js +0 -1
- package/dist/features/email/email.provider.d.ts +0 -37
- package/dist/shared/content.repository.d1.d.ts +0 -68
- package/dist/upload.d.ts +0 -16
- package/dist/auth/{bcrypt-hash-provider.d.ts → providers/hash.provider.d.ts} +0 -0
- package/dist/auth/{jose-token-service.d.ts → providers/jwt-token.service.d.ts} +0 -0
- package/dist/auth/{login.d.ts → utils/login-helpers.d.ts} +0 -0
- package/dist/auth/{refresh.d.ts → utils/refresh-token.d.ts} +0 -0
- package/dist/features/automations/{automations.schema.d.ts → api/automations.schema.d.ts} +16 -16
- /package/dist/features/automations/{automation-runner.d.ts → engine/automation-runner.d.ts} +0 -0
- /package/dist/features/automations/{cron-runner.d.ts → engine/cron-runner.d.ts} +0 -0
- /package/dist/features/automations/{cron-runner.utils.d.ts → engine/cron-runner.utils.d.ts} +0 -0
- /package/dist/features/automations/{context-resolver.d.ts → evaluator/context-resolver.d.ts} +0 -0
- /package/dist/features/automations/{template-grammar.d.ts → evaluator/template-grammar.d.ts} +0 -0
- /package/dist/features/automations/{var-access-resolver.d.ts → evaluator/var-access-resolver.d.ts} +0 -0
- /package/dist/features/automations/{action-executors → executors}/create-entry.executor.d.ts +0 -0
- /package/dist/features/automations/{filter-translation.d.ts → filters/filter-translation.d.ts} +0 -0
- /package/dist/features/automations/{when-pushdown.d.ts → filters/when-pushdown.d.ts} +0 -0
- /package/dist/{search-utils.d.ts → features/search/search-utils.d.ts} +0 -0
- /package/dist/shared/{demo-data-sql.d.ts → db/migrations/demo-data-sql.d.ts} +0 -0
- /package/dist/shared/{automations.repository.d1.d.ts → db/repositories/automations.repository.d1.d.ts} +0 -0
- /package/dist/shared/{base.repository.d1.d.ts → db/repositories/base.repository.d1.d.ts} +0 -0
- /package/dist/shared/{d1-activity-log.repository.d.ts → db/repositories/d1-activity-log.repository.d.ts} +0 -0
- /package/dist/shared/{d1-analytics.repository.d.ts → db/repositories/d1-analytics.repository.d.ts} +0 -0
- /package/dist/shared/{d1-content-scan.repository.d.ts → db/repositories/d1-content-scan.repository.d.ts} +0 -0
- /package/dist/shared/{d1-notification.repository.d.ts → db/repositories/d1-notification.repository.d.ts} +0 -0
- /package/dist/shared/{d1-password-reset-token.repository.d.ts → db/repositories/d1-password-reset-token.repository.d.ts} +0 -0
- /package/dist/shared/{d1-search.repository.d.ts → db/repositories/d1-search.repository.d.ts} +0 -0
- /package/dist/shared/{d1-session.repository.d.ts → db/repositories/d1-session.repository.d.ts} +0 -0
- /package/dist/shared/{d1-setup-checklist.repository.d.ts → db/repositories/d1-setup-checklist.repository.d.ts} +0 -0
- /package/dist/shared/{d1-user.repository.d.ts → db/repositories/d1-user.repository.d.ts} +0 -0
- /package/dist/shared/{d1-widget.repository.d.ts → db/repositories/d1-widget.repository.d.ts} +0 -0
- /package/dist/shared/{dashboard-layout.repository.d1.d.ts → db/repositories/dashboard-layout.repository.d1.d.ts} +0 -0
- /package/dist/shared/{demo-data.repository.d1.d.ts → db/repositories/demo-data.repository.d1.d.ts} +0 -0
- /package/dist/shared/{idempotency.repository.d1.d.ts → db/repositories/idempotency.repository.d1.d.ts} +0 -0
- /package/dist/shared/{in-memory-seed.repository.d.ts → db/repositories/in-memory-seed.repository.d.ts} +0 -0
- /package/dist/shared/{media.repository.d1.d.ts → db/repositories/media.repository.d1.d.ts} +0 -0
- /package/dist/shared/{seed.repository.d1.d.ts → db/repositories/seed.repository.d1.d.ts} +0 -0
- /package/dist/shared/{site-settings.repository.d1.d.ts → db/repositories/site-settings.repository.d1.d.ts} +0 -0
- /package/dist/shared/{system-stats.repository.d1.d.ts → db/repositories/system-stats.repository.d1.d.ts} +0 -0
- /package/dist/{features → shared}/email/email.service.d.ts +0 -0
- /package/dist/{features → shared}/email/index.d.ts +0 -0
- /package/dist/{features → shared}/email/templates/automation-mail.d.ts +0 -0
- /package/dist/{features → shared}/email/templates/password-changed.d.ts +0 -0
- /package/dist/{features → shared}/email/templates/password-reset.d.ts +0 -0
- /package/dist/{features → shared}/email/templates/shell.d.ts +0 -0
- /package/dist/shared/{fts-sync.d.ts → jobs/fts-sync.d.ts} +0 -0
- /package/dist/shared/{apply-policies.d.ts → policies/apply-policies.d.ts} +0 -0
- /package/dist/shared/{d1-activity-logger.d.ts → services/activity-log/d1-activity-logger.d.ts} +0 -0
- /package/dist/shared/{in-memory-activity-logger.d.ts → services/activity-log/in-memory-activity-logger.d.ts} +0 -0
- /package/dist/shared/{seed-registry-cache.d.ts → services/cache/seed-registry-cache.d.ts} +0 -0
- /package/dist/shared/{fixed-clock.d.ts → services/clock/fixed-clock.d.ts} +0 -0
- /package/dist/shared/{sequential-id-generator.d.ts → services/id-generator/sequential-id-generator.d.ts} +0 -0
- /package/dist/shared/{background-notification-service.d.ts → services/notification/background-notification-service.d.ts} +0 -0
- /package/dist/shared/{in-memory-notification-service.d.ts → services/notification/in-memory-notification-service.d.ts} +0 -0
- /package/dist/shared/{qstash-notification-service.d.ts → services/notification/qstash-notification-service.d.ts} +0 -0
- /package/dist/shared/{execution-context-scheduler.d.ts → services/scheduler/execution-context-scheduler.d.ts} +0 -0
- /package/dist/shared/{content-utils.d.ts → utils/content-utils.d.ts} +0 -0
- /package/dist/shared/{query-utils.d.ts → utils/query-utils.d.ts} +0 -0
- /package/dist/shared/{request-utils.d.ts → utils/request-utils.d.ts} +0 -0
- /package/dist/shared/{storage-utils.d.ts → utils/storage-utils.d.ts} +0 -0
|
@@ -1,265 +1,265 @@
|
|
|
1
|
-
-- =============================================================================
|
|
2
|
-
-- Beech CMS v0.4.0 — Base Schema
|
|
3
|
-
--
|
|
4
|
-
-- Single migration for fresh installations. Creates all system tables.
|
|
5
|
-
--
|
|
6
|
-
-- Content tables (content_{slug}, fts_{slug}, content_{slug}_drafts) are
|
|
7
|
-
-- NOT defined here — they are generated at deploy time by: beech seed:load
|
|
8
|
-
-- FTS indexes text + richtext branches (policies.search !== false).
|
|
9
|
-
--
|
|
10
|
-
-- Usage:
|
|
11
|
-
-- wrangler d1 execute beech-db --file=migrations/0000_v040_base.sql (remote)
|
|
12
|
-
-- wrangler d1 execute beech-db --local --file=migrations/0000_v040_base.sql (local)
|
|
13
|
-
--
|
|
14
|
-
-- After this migration, run:
|
|
15
|
-
-- beech seed:load → creates content_{slug} tables + FTS + triggers
|
|
16
|
-
-- POST /auth/setup → creates first admin user
|
|
17
|
-
-- =============================================================================
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
-- =============================================================================
|
|
21
|
-
-- 1. USERS
|
|
22
|
-
-- Dashboard users (admins + editors). Passwords stored as bcrypt hashes.
|
|
23
|
-
-- Profile fields (name, avatar_url, notification_prefs) merged in from
|
|
24
|
-
-- the start — no incremental ALTER TABLE needed.
|
|
25
|
-
-- =============================================================================
|
|
26
|
-
|
|
27
|
-
CREATE TABLE IF NOT EXISTS users (
|
|
28
|
-
id TEXT NOT NULL PRIMARY KEY,
|
|
29
|
-
email TEXT NOT NULL UNIQUE,
|
|
30
|
-
password_hash TEXT NOT NULL,
|
|
31
|
-
role TEXT NOT NULL DEFAULT 'editor' CHECK (role IN ('admin', 'editor')),
|
|
32
|
-
name TEXT,
|
|
33
|
-
surname TEXT,
|
|
34
|
-
avatar_url TEXT,
|
|
35
|
-
notification_prefs TEXT NOT NULL DEFAULT '{}',
|
|
36
|
-
created_at INTEGER NOT NULL DEFAULT (unixepoch())
|
|
37
|
-
);
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
-- =============================================================================
|
|
41
|
-
-- 2. REFRESH TOKENS
|
|
42
|
-
-- JWT refresh token rotation. Stored as SHA-256 hashes, never plaintext.
|
|
43
|
-
-- revoked_at IS NULL = active token.
|
|
44
|
-
-- =============================================================================
|
|
45
|
-
|
|
46
|
-
CREATE TABLE IF NOT EXISTS refresh_tokens (
|
|
47
|
-
id TEXT NOT NULL PRIMARY KEY,
|
|
48
|
-
user_id TEXT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
|
49
|
-
token_hash TEXT NOT NULL,
|
|
50
|
-
expires_at INTEGER NOT NULL,
|
|
51
|
-
created_at INTEGER NOT NULL DEFAULT (unixepoch()),
|
|
52
|
-
revoked_at INTEGER DEFAULT NULL
|
|
53
|
-
);
|
|
54
|
-
|
|
55
|
-
CREATE INDEX IF NOT EXISTS idx_refresh_user ON refresh_tokens(user_id);
|
|
56
|
-
CREATE INDEX IF NOT EXISTS idx_refresh_hash ON refresh_tokens(token_hash);
|
|
57
|
-
CREATE INDEX IF NOT EXISTS idx_refresh_expires ON refresh_tokens(expires_at);
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
-- =============================================================================
|
|
61
|
-
-- 3. PASSWORD RESET TOKENS
|
|
62
|
-
-- Single-use, 30-minute TTL, stored as SHA-256 hashes.
|
|
63
|
-
-- used_at set on redemption to prevent replay attacks.
|
|
64
|
-
-- =============================================================================
|
|
65
|
-
|
|
66
|
-
CREATE TABLE IF NOT EXISTS password_reset_tokens (
|
|
67
|
-
id TEXT NOT NULL PRIMARY KEY,
|
|
68
|
-
user_id TEXT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
|
69
|
-
token_hash TEXT NOT NULL,
|
|
70
|
-
expires_at INTEGER NOT NULL,
|
|
71
|
-
created_at INTEGER NOT NULL DEFAULT (unixepoch()),
|
|
72
|
-
used_at INTEGER DEFAULT NULL
|
|
73
|
-
);
|
|
74
|
-
|
|
75
|
-
CREATE INDEX IF NOT EXISTS idx_prt_hash ON password_reset_tokens(token_hash);
|
|
76
|
-
CREATE INDEX IF NOT EXISTS idx_prt_user ON password_reset_tokens(user_id);
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
-- =============================================================================
|
|
80
|
-
-- 4. PUBLIC API — IDEMPOTENCY KEYS
|
|
81
|
-
-- Deduplicates POST requests from public consumers (e.g. contact forms).
|
|
82
|
-
-- expires_at-based pruning keeps the table small.
|
|
83
|
-
-- =============================================================================
|
|
84
|
-
|
|
85
|
-
CREATE TABLE IF NOT EXISTS public_idempotency_keys (
|
|
86
|
-
idempotency_key TEXT NOT NULL PRIMARY KEY,
|
|
87
|
-
request_fingerprint TEXT NOT NULL,
|
|
88
|
-
response_status INTEGER NOT NULL,
|
|
89
|
-
response_body TEXT NOT NULL,
|
|
90
|
-
created_at INTEGER NOT NULL,
|
|
91
|
-
expires_at INTEGER NOT NULL
|
|
92
|
-
);
|
|
93
|
-
|
|
94
|
-
CREATE INDEX IF NOT EXISTS idx_idempotency_expires ON public_idempotency_keys(expires_at);
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
-- =============================================================================
|
|
98
|
-
-- 5. ANALYTICS
|
|
99
|
-
-- Daily metric counters per seed and global (seed = '' sentinel).
|
|
100
|
-
-- Metrics: 'requests' | 'visitors' | 'bandwidth_mb'
|
|
101
|
-
-- =============================================================================
|
|
102
|
-
|
|
103
|
-
CREATE TABLE IF NOT EXISTS analytics (
|
|
104
|
-
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
|
105
|
-
day_ts INTEGER NOT NULL,
|
|
106
|
-
metric TEXT NOT NULL,
|
|
107
|
-
seed TEXT NOT NULL DEFAULT '',
|
|
108
|
-
value INTEGER NOT NULL DEFAULT 0,
|
|
109
|
-
UNIQUE(day_ts, metric, seed)
|
|
110
|
-
);
|
|
111
|
-
|
|
112
|
-
CREATE INDEX IF NOT EXISTS idx_analytics_day ON analytics(day_ts);
|
|
113
|
-
CREATE INDEX IF NOT EXISTS idx_analytics_seed ON analytics(seed, day_ts);
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
-- =============================================================================
|
|
117
|
-
-- 6. SYSTEM STATS
|
|
118
|
-
-- Persistent key-value store for system-level counters.
|
|
119
|
-
-- 'total_storage_bytes' is kept for dashboard widgets;
|
|
120
|
-
-- SUM(size_bytes) FROM media_objects is the authoritative source.
|
|
121
|
-
-- =============================================================================
|
|
122
|
-
|
|
123
|
-
CREATE TABLE IF NOT EXISTS system_stats (
|
|
124
|
-
id TEXT NOT NULL PRIMARY KEY,
|
|
125
|
-
value TEXT NOT NULL
|
|
126
|
-
);
|
|
127
|
-
|
|
128
|
-
INSERT OR IGNORE INTO system_stats (id, value) VALUES ('total_storage_bytes', '0');
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
-- =============================================================================
|
|
132
|
-
-- 7. ACTIVITY LOGS
|
|
133
|
-
-- Append-only audit log. No FK on user_id — deleted users are retained
|
|
134
|
-
-- for compliance. user_name denormalized to survive user deletions.
|
|
135
|
-
-- Actions: 'create' | 'update' | 'delete' | 'upload'
|
|
136
|
-
-- Entity types: 'content' | 'media'
|
|
137
|
-
-- =============================================================================
|
|
138
|
-
|
|
139
|
-
CREATE TABLE IF NOT EXISTS activity_logs (
|
|
140
|
-
id TEXT NOT NULL PRIMARY KEY,
|
|
141
|
-
user_id TEXT NOT NULL,
|
|
142
|
-
user_email TEXT NOT NULL,
|
|
143
|
-
user_name TEXT,
|
|
144
|
-
action TEXT NOT NULL,
|
|
145
|
-
entity_type TEXT NOT NULL,
|
|
146
|
-
entity_id TEXT NOT NULL,
|
|
147
|
-
entity_slug TEXT,
|
|
148
|
-
details TEXT,
|
|
149
|
-
created_at INTEGER NOT NULL DEFAULT (unixepoch())
|
|
150
|
-
);
|
|
151
|
-
|
|
152
|
-
CREATE INDEX IF NOT EXISTS idx_activity_user ON activity_logs(user_id);
|
|
153
|
-
CREATE INDEX IF NOT EXISTS idx_activity_created ON activity_logs(created_at);
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
-- =============================================================================
|
|
157
|
-
-- 8. NOTIFICATIONS
|
|
158
|
-
-- In-app notification inbox for system events (e.g. new form submission).
|
|
159
|
-
-- is_read: 0 = unread, 1 = read.
|
|
160
|
-
-- =============================================================================
|
|
161
|
-
|
|
162
|
-
CREATE TABLE IF NOT EXISTS notifications (
|
|
163
|
-
id TEXT NOT NULL PRIMARY KEY,
|
|
164
|
-
title TEXT NOT NULL,
|
|
165
|
-
message TEXT NOT NULL,
|
|
166
|
-
type TEXT NOT NULL DEFAULT 'info' CHECK (type IN ('info', 'warning', 'error')),
|
|
167
|
-
is_read INTEGER NOT NULL DEFAULT 0 CHECK (is_read IN (0, 1)),
|
|
168
|
-
created_at INTEGER NOT NULL DEFAULT (unixepoch())
|
|
169
|
-
);
|
|
170
|
-
|
|
171
|
-
CREATE INDEX IF NOT EXISTS idx_notifications_created ON notifications(created_at);
|
|
172
|
-
CREATE INDEX IF NOT EXISTS idx_notifications_unread ON notifications(is_read);
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
-- =============================================================================
|
|
176
|
-
-- 9. MEDIA OBJECTS
|
|
177
|
-
-- Tracks every file uploaded to R2. Enables media library UI, orphan
|
|
178
|
-
-- detection, and storage reporting. No FK on uploaded_by for D1 portability.
|
|
179
|
-
-- =============================================================================
|
|
180
|
-
|
|
181
|
-
CREATE TABLE IF NOT EXISTS media_objects (
|
|
182
|
-
key TEXT NOT NULL PRIMARY KEY,
|
|
183
|
-
filename TEXT NOT NULL,
|
|
184
|
-
mime_type TEXT NOT NULL,
|
|
185
|
-
size_bytes INTEGER NOT NULL,
|
|
186
|
-
uploaded_by TEXT NOT NULL DEFAULT '',
|
|
187
|
-
created_at INTEGER NOT NULL DEFAULT (unixepoch())
|
|
188
|
-
);
|
|
189
|
-
|
|
190
|
-
CREATE INDEX IF NOT EXISTS idx_media_user ON media_objects(uploaded_by);
|
|
191
|
-
CREATE INDEX IF NOT EXISTS idx_media_created ON media_objects(created_at DESC);
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
-- =============================================================================
|
|
195
|
-
-- 10. CONTENT EVENT LOG
|
|
196
|
-
-- Lightweight event log for activity feed and dashboard stats.
|
|
197
|
-
-- Does NOT store field data — only event metadata (who did what, when).
|
|
198
|
-
-- Replaces the legacy content_entries table as cross-seed event source.
|
|
199
|
-
-- The actual content lives in content_{slug} tables (created by seed:load).
|
|
200
|
-
-- =============================================================================
|
|
201
|
-
|
|
202
|
-
CREATE TABLE IF NOT EXISTS content_event_log (
|
|
203
|
-
id TEXT NOT NULL PRIMARY KEY,
|
|
204
|
-
schema_slug TEXT NOT NULL,
|
|
205
|
-
entry_id TEXT NOT NULL,
|
|
206
|
-
action TEXT NOT NULL CHECK (action IN ('create', 'update', 'delete')),
|
|
207
|
-
user_id TEXT,
|
|
208
|
-
details TEXT,
|
|
209
|
-
created_at INTEGER NOT NULL DEFAULT (unixepoch())
|
|
210
|
-
);
|
|
211
|
-
|
|
212
|
-
CREATE INDEX IF NOT EXISTS idx_event_log_schema_slug ON content_event_log(schema_slug);
|
|
213
|
-
CREATE INDEX IF NOT EXISTS idx_event_log_created_at ON content_event_log(created_at DESC);
|
|
214
|
-
CREATE INDEX IF NOT EXISTS idx_event_log_entry_id ON content_event_log(entry_id);
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
-- =============================================================================
|
|
218
|
-
-- 11. AUTOMATIONS
|
|
219
|
-
-- Event-driven automation rules. Each automation defines one or more
|
|
220
|
-
-- triggers (JSON array of {event, cron?}), optional WhenNode conditions,
|
|
221
|
-
-- and a sequence of actions to execute.
|
|
222
|
-
-- triggers: [{ event: 'create'|'update'|'delete'|'cron', cron?: string }]
|
|
223
|
-
-- Max one cron trigger per automation, enforced at the application layer.
|
|
224
|
-
-- =============================================================================
|
|
225
|
-
|
|
226
|
-
CREATE TABLE IF NOT EXISTS automations (
|
|
227
|
-
id TEXT NOT NULL PRIMARY KEY,
|
|
228
|
-
seed_slug TEXT NOT NULL,
|
|
229
|
-
name TEXT NOT NULL,
|
|
230
|
-
enabled INTEGER NOT NULL DEFAULT 1,
|
|
231
|
-
triggers TEXT NOT NULL DEFAULT '[]',
|
|
232
|
-
trigger_conditions TEXT,
|
|
233
|
-
actions TEXT NOT NULL,
|
|
234
|
-
created_at INTEGER NOT NULL DEFAULT (unixepoch()),
|
|
235
|
-
updated_at INTEGER NOT NULL DEFAULT (unixepoch())
|
|
236
|
-
);
|
|
237
|
-
|
|
238
|
-
CREATE INDEX IF NOT EXISTS idx_automations_seed_slug ON automations(seed_slug);
|
|
239
|
-
CREATE INDEX IF NOT EXISTS idx_automations_enabled ON automations(enabled);
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
-- =============================================================================
|
|
243
|
-
-- 12. SITE SETTINGS
|
|
244
|
-
-- Key-value store for site-level configuration (title, locale, timezone…).
|
|
245
|
-
-- =============================================================================
|
|
246
|
-
|
|
247
|
-
CREATE TABLE IF NOT EXISTS site_settings (
|
|
248
|
-
key TEXT NOT NULL PRIMARY KEY,
|
|
249
|
-
value TEXT NOT NULL
|
|
250
|
-
);
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
-- =============================================================================
|
|
254
|
-
-- 13. SEED LAYOUTS
|
|
255
|
-
-- Persists per-Seed custom editor form layouts (sprint 04a).
|
|
256
|
-
-- layout column stores a FormLayout JSON blob.
|
|
257
|
-
-- Reset = DELETE the row; client recomputes the generated default.
|
|
258
|
-
-- =============================================================================
|
|
259
|
-
|
|
260
|
-
CREATE TABLE IF NOT EXISTS seed_layouts (
|
|
261
|
-
slug TEXT NOT NULL PRIMARY KEY,
|
|
262
|
-
layout TEXT NOT NULL, -- JSON of FormLayout
|
|
263
|
-
updated_at INTEGER NOT NULL DEFAULT (unixepoch()),
|
|
264
|
-
updated_by TEXT NOT NULL -- users.id of the writer
|
|
265
|
-
);
|
|
1
|
+
-- =============================================================================
|
|
2
|
+
-- Beech CMS v0.4.0 — Base Schema
|
|
3
|
+
--
|
|
4
|
+
-- Single migration for fresh installations. Creates all system tables.
|
|
5
|
+
--
|
|
6
|
+
-- Content tables (content_{slug}, fts_{slug}, content_{slug}_drafts) are
|
|
7
|
+
-- NOT defined here — they are generated at deploy time by: beech seed:load
|
|
8
|
+
-- FTS indexes text + richtext branches (policies.search !== false).
|
|
9
|
+
--
|
|
10
|
+
-- Usage:
|
|
11
|
+
-- wrangler d1 execute beech-db --file=migrations/0000_v040_base.sql (remote)
|
|
12
|
+
-- wrangler d1 execute beech-db --local --file=migrations/0000_v040_base.sql (local)
|
|
13
|
+
--
|
|
14
|
+
-- After this migration, run:
|
|
15
|
+
-- beech seed:load → creates content_{slug} tables + FTS + triggers
|
|
16
|
+
-- POST /auth/setup → creates first admin user
|
|
17
|
+
-- =============================================================================
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
-- =============================================================================
|
|
21
|
+
-- 1. USERS
|
|
22
|
+
-- Dashboard users (admins + editors). Passwords stored as bcrypt hashes.
|
|
23
|
+
-- Profile fields (name, avatar_url, notification_prefs) merged in from
|
|
24
|
+
-- the start — no incremental ALTER TABLE needed.
|
|
25
|
+
-- =============================================================================
|
|
26
|
+
|
|
27
|
+
CREATE TABLE IF NOT EXISTS users (
|
|
28
|
+
id TEXT NOT NULL PRIMARY KEY,
|
|
29
|
+
email TEXT NOT NULL UNIQUE,
|
|
30
|
+
password_hash TEXT NOT NULL,
|
|
31
|
+
role TEXT NOT NULL DEFAULT 'editor' CHECK (role IN ('admin', 'editor')),
|
|
32
|
+
name TEXT,
|
|
33
|
+
surname TEXT,
|
|
34
|
+
avatar_url TEXT,
|
|
35
|
+
notification_prefs TEXT NOT NULL DEFAULT '{}',
|
|
36
|
+
created_at INTEGER NOT NULL DEFAULT (unixepoch())
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
-- =============================================================================
|
|
41
|
+
-- 2. REFRESH TOKENS
|
|
42
|
+
-- JWT refresh token rotation. Stored as SHA-256 hashes, never plaintext.
|
|
43
|
+
-- revoked_at IS NULL = active token.
|
|
44
|
+
-- =============================================================================
|
|
45
|
+
|
|
46
|
+
CREATE TABLE IF NOT EXISTS refresh_tokens (
|
|
47
|
+
id TEXT NOT NULL PRIMARY KEY,
|
|
48
|
+
user_id TEXT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
|
49
|
+
token_hash TEXT NOT NULL,
|
|
50
|
+
expires_at INTEGER NOT NULL,
|
|
51
|
+
created_at INTEGER NOT NULL DEFAULT (unixepoch()),
|
|
52
|
+
revoked_at INTEGER DEFAULT NULL
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
CREATE INDEX IF NOT EXISTS idx_refresh_user ON refresh_tokens(user_id);
|
|
56
|
+
CREATE INDEX IF NOT EXISTS idx_refresh_hash ON refresh_tokens(token_hash);
|
|
57
|
+
CREATE INDEX IF NOT EXISTS idx_refresh_expires ON refresh_tokens(expires_at);
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
-- =============================================================================
|
|
61
|
+
-- 3. PASSWORD RESET TOKENS
|
|
62
|
+
-- Single-use, 30-minute TTL, stored as SHA-256 hashes.
|
|
63
|
+
-- used_at set on redemption to prevent replay attacks.
|
|
64
|
+
-- =============================================================================
|
|
65
|
+
|
|
66
|
+
CREATE TABLE IF NOT EXISTS password_reset_tokens (
|
|
67
|
+
id TEXT NOT NULL PRIMARY KEY,
|
|
68
|
+
user_id TEXT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
|
69
|
+
token_hash TEXT NOT NULL,
|
|
70
|
+
expires_at INTEGER NOT NULL,
|
|
71
|
+
created_at INTEGER NOT NULL DEFAULT (unixepoch()),
|
|
72
|
+
used_at INTEGER DEFAULT NULL
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
CREATE INDEX IF NOT EXISTS idx_prt_hash ON password_reset_tokens(token_hash);
|
|
76
|
+
CREATE INDEX IF NOT EXISTS idx_prt_user ON password_reset_tokens(user_id);
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
-- =============================================================================
|
|
80
|
+
-- 4. PUBLIC API — IDEMPOTENCY KEYS
|
|
81
|
+
-- Deduplicates POST requests from public consumers (e.g. contact forms).
|
|
82
|
+
-- expires_at-based pruning keeps the table small.
|
|
83
|
+
-- =============================================================================
|
|
84
|
+
|
|
85
|
+
CREATE TABLE IF NOT EXISTS public_idempotency_keys (
|
|
86
|
+
idempotency_key TEXT NOT NULL PRIMARY KEY,
|
|
87
|
+
request_fingerprint TEXT NOT NULL,
|
|
88
|
+
response_status INTEGER NOT NULL,
|
|
89
|
+
response_body TEXT NOT NULL,
|
|
90
|
+
created_at INTEGER NOT NULL,
|
|
91
|
+
expires_at INTEGER NOT NULL
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
CREATE INDEX IF NOT EXISTS idx_idempotency_expires ON public_idempotency_keys(expires_at);
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
-- =============================================================================
|
|
98
|
+
-- 5. ANALYTICS
|
|
99
|
+
-- Daily metric counters per seed and global (seed = '' sentinel).
|
|
100
|
+
-- Metrics: 'requests' | 'visitors' | 'bandwidth_mb'
|
|
101
|
+
-- =============================================================================
|
|
102
|
+
|
|
103
|
+
CREATE TABLE IF NOT EXISTS analytics (
|
|
104
|
+
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
|
105
|
+
day_ts INTEGER NOT NULL,
|
|
106
|
+
metric TEXT NOT NULL,
|
|
107
|
+
seed TEXT NOT NULL DEFAULT '',
|
|
108
|
+
value INTEGER NOT NULL DEFAULT 0,
|
|
109
|
+
UNIQUE(day_ts, metric, seed)
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
CREATE INDEX IF NOT EXISTS idx_analytics_day ON analytics(day_ts);
|
|
113
|
+
CREATE INDEX IF NOT EXISTS idx_analytics_seed ON analytics(seed, day_ts);
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
-- =============================================================================
|
|
117
|
+
-- 6. SYSTEM STATS
|
|
118
|
+
-- Persistent key-value store for system-level counters.
|
|
119
|
+
-- 'total_storage_bytes' is kept for dashboard widgets;
|
|
120
|
+
-- SUM(size_bytes) FROM media_objects is the authoritative source.
|
|
121
|
+
-- =============================================================================
|
|
122
|
+
|
|
123
|
+
CREATE TABLE IF NOT EXISTS system_stats (
|
|
124
|
+
id TEXT NOT NULL PRIMARY KEY,
|
|
125
|
+
value TEXT NOT NULL
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
INSERT OR IGNORE INTO system_stats (id, value) VALUES ('total_storage_bytes', '0');
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
-- =============================================================================
|
|
132
|
+
-- 7. ACTIVITY LOGS
|
|
133
|
+
-- Append-only audit log. No FK on user_id — deleted users are retained
|
|
134
|
+
-- for compliance. user_name denormalized to survive user deletions.
|
|
135
|
+
-- Actions: 'create' | 'update' | 'delete' | 'upload'
|
|
136
|
+
-- Entity types: 'content' | 'media'
|
|
137
|
+
-- =============================================================================
|
|
138
|
+
|
|
139
|
+
CREATE TABLE IF NOT EXISTS activity_logs (
|
|
140
|
+
id TEXT NOT NULL PRIMARY KEY,
|
|
141
|
+
user_id TEXT NOT NULL,
|
|
142
|
+
user_email TEXT NOT NULL,
|
|
143
|
+
user_name TEXT,
|
|
144
|
+
action TEXT NOT NULL,
|
|
145
|
+
entity_type TEXT NOT NULL,
|
|
146
|
+
entity_id TEXT NOT NULL,
|
|
147
|
+
entity_slug TEXT,
|
|
148
|
+
details TEXT,
|
|
149
|
+
created_at INTEGER NOT NULL DEFAULT (unixepoch())
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
CREATE INDEX IF NOT EXISTS idx_activity_user ON activity_logs(user_id);
|
|
153
|
+
CREATE INDEX IF NOT EXISTS idx_activity_created ON activity_logs(created_at);
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
-- =============================================================================
|
|
157
|
+
-- 8. NOTIFICATIONS
|
|
158
|
+
-- In-app notification inbox for system events (e.g. new form submission).
|
|
159
|
+
-- is_read: 0 = unread, 1 = read.
|
|
160
|
+
-- =============================================================================
|
|
161
|
+
|
|
162
|
+
CREATE TABLE IF NOT EXISTS notifications (
|
|
163
|
+
id TEXT NOT NULL PRIMARY KEY,
|
|
164
|
+
title TEXT NOT NULL,
|
|
165
|
+
message TEXT NOT NULL,
|
|
166
|
+
type TEXT NOT NULL DEFAULT 'info' CHECK (type IN ('info', 'warning', 'error')),
|
|
167
|
+
is_read INTEGER NOT NULL DEFAULT 0 CHECK (is_read IN (0, 1)),
|
|
168
|
+
created_at INTEGER NOT NULL DEFAULT (unixepoch())
|
|
169
|
+
);
|
|
170
|
+
|
|
171
|
+
CREATE INDEX IF NOT EXISTS idx_notifications_created ON notifications(created_at);
|
|
172
|
+
CREATE INDEX IF NOT EXISTS idx_notifications_unread ON notifications(is_read);
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
-- =============================================================================
|
|
176
|
+
-- 9. MEDIA OBJECTS
|
|
177
|
+
-- Tracks every file uploaded to R2. Enables media library UI, orphan
|
|
178
|
+
-- detection, and storage reporting. No FK on uploaded_by for D1 portability.
|
|
179
|
+
-- =============================================================================
|
|
180
|
+
|
|
181
|
+
CREATE TABLE IF NOT EXISTS media_objects (
|
|
182
|
+
key TEXT NOT NULL PRIMARY KEY,
|
|
183
|
+
filename TEXT NOT NULL,
|
|
184
|
+
mime_type TEXT NOT NULL,
|
|
185
|
+
size_bytes INTEGER NOT NULL,
|
|
186
|
+
uploaded_by TEXT NOT NULL DEFAULT '',
|
|
187
|
+
created_at INTEGER NOT NULL DEFAULT (unixepoch())
|
|
188
|
+
);
|
|
189
|
+
|
|
190
|
+
CREATE INDEX IF NOT EXISTS idx_media_user ON media_objects(uploaded_by);
|
|
191
|
+
CREATE INDEX IF NOT EXISTS idx_media_created ON media_objects(created_at DESC);
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
-- =============================================================================
|
|
195
|
+
-- 10. CONTENT EVENT LOG
|
|
196
|
+
-- Lightweight event log for activity feed and dashboard stats.
|
|
197
|
+
-- Does NOT store field data — only event metadata (who did what, when).
|
|
198
|
+
-- Replaces the legacy content_entries table as cross-seed event source.
|
|
199
|
+
-- The actual content lives in content_{slug} tables (created by seed:load).
|
|
200
|
+
-- =============================================================================
|
|
201
|
+
|
|
202
|
+
CREATE TABLE IF NOT EXISTS content_event_log (
|
|
203
|
+
id TEXT NOT NULL PRIMARY KEY,
|
|
204
|
+
schema_slug TEXT NOT NULL,
|
|
205
|
+
entry_id TEXT NOT NULL,
|
|
206
|
+
action TEXT NOT NULL CHECK (action IN ('create', 'update', 'delete')),
|
|
207
|
+
user_id TEXT,
|
|
208
|
+
details TEXT,
|
|
209
|
+
created_at INTEGER NOT NULL DEFAULT (unixepoch())
|
|
210
|
+
);
|
|
211
|
+
|
|
212
|
+
CREATE INDEX IF NOT EXISTS idx_event_log_schema_slug ON content_event_log(schema_slug);
|
|
213
|
+
CREATE INDEX IF NOT EXISTS idx_event_log_created_at ON content_event_log(created_at DESC);
|
|
214
|
+
CREATE INDEX IF NOT EXISTS idx_event_log_entry_id ON content_event_log(entry_id);
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
-- =============================================================================
|
|
218
|
+
-- 11. AUTOMATIONS
|
|
219
|
+
-- Event-driven automation rules. Each automation defines one or more
|
|
220
|
+
-- triggers (JSON array of {event, cron?}), optional WhenNode conditions,
|
|
221
|
+
-- and a sequence of actions to execute.
|
|
222
|
+
-- triggers: [{ event: 'create'|'update'|'delete'|'cron', cron?: string }]
|
|
223
|
+
-- Max one cron trigger per automation, enforced at the application layer.
|
|
224
|
+
-- =============================================================================
|
|
225
|
+
|
|
226
|
+
CREATE TABLE IF NOT EXISTS automations (
|
|
227
|
+
id TEXT NOT NULL PRIMARY KEY,
|
|
228
|
+
seed_slug TEXT NOT NULL,
|
|
229
|
+
name TEXT NOT NULL,
|
|
230
|
+
enabled INTEGER NOT NULL DEFAULT 1,
|
|
231
|
+
triggers TEXT NOT NULL DEFAULT '[]',
|
|
232
|
+
trigger_conditions TEXT,
|
|
233
|
+
actions TEXT NOT NULL,
|
|
234
|
+
created_at INTEGER NOT NULL DEFAULT (unixepoch()),
|
|
235
|
+
updated_at INTEGER NOT NULL DEFAULT (unixepoch())
|
|
236
|
+
);
|
|
237
|
+
|
|
238
|
+
CREATE INDEX IF NOT EXISTS idx_automations_seed_slug ON automations(seed_slug);
|
|
239
|
+
CREATE INDEX IF NOT EXISTS idx_automations_enabled ON automations(enabled);
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
-- =============================================================================
|
|
243
|
+
-- 12. SITE SETTINGS
|
|
244
|
+
-- Key-value store for site-level configuration (title, locale, timezone…).
|
|
245
|
+
-- =============================================================================
|
|
246
|
+
|
|
247
|
+
CREATE TABLE IF NOT EXISTS site_settings (
|
|
248
|
+
key TEXT NOT NULL PRIMARY KEY,
|
|
249
|
+
value TEXT NOT NULL
|
|
250
|
+
);
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
-- =============================================================================
|
|
254
|
+
-- 13. SEED LAYOUTS
|
|
255
|
+
-- Persists per-Seed custom editor form layouts (sprint 04a).
|
|
256
|
+
-- layout column stores a FormLayout JSON blob.
|
|
257
|
+
-- Reset = DELETE the row; client recomputes the generated default.
|
|
258
|
+
-- =============================================================================
|
|
259
|
+
|
|
260
|
+
CREATE TABLE IF NOT EXISTS seed_layouts (
|
|
261
|
+
slug TEXT NOT NULL PRIMARY KEY,
|
|
262
|
+
layout TEXT NOT NULL, -- JSON of FormLayout
|
|
263
|
+
updated_at INTEGER NOT NULL DEFAULT (unixepoch()),
|
|
264
|
+
updated_by TEXT NOT NULL -- users.id of the writer
|
|
265
|
+
);
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
CREATE TABLE IF NOT EXISTS automations (
|
|
2
|
-
id TEXT NOT NULL PRIMARY KEY,
|
|
3
|
-
seed_slug TEXT NOT NULL,
|
|
4
|
-
name TEXT NOT NULL,
|
|
5
|
-
enabled INTEGER NOT NULL DEFAULT 1,
|
|
6
|
-
triggers TEXT NOT NULL DEFAULT '[]',
|
|
7
|
-
trigger_conditions TEXT,
|
|
8
|
-
actions TEXT NOT NULL,
|
|
9
|
-
created_at INTEGER NOT NULL DEFAULT (unixepoch()),
|
|
10
|
-
updated_at INTEGER NOT NULL DEFAULT (unixepoch())
|
|
11
|
-
);
|
|
12
|
-
|
|
13
|
-
CREATE INDEX IF NOT EXISTS idx_automations_seed_slug ON automations(seed_slug);
|
|
14
|
-
CREATE INDEX IF NOT EXISTS idx_automations_enabled ON automations(enabled);
|
|
1
|
+
CREATE TABLE IF NOT EXISTS automations (
|
|
2
|
+
id TEXT NOT NULL PRIMARY KEY,
|
|
3
|
+
seed_slug TEXT NOT NULL,
|
|
4
|
+
name TEXT NOT NULL,
|
|
5
|
+
enabled INTEGER NOT NULL DEFAULT 1,
|
|
6
|
+
triggers TEXT NOT NULL DEFAULT '[]',
|
|
7
|
+
trigger_conditions TEXT,
|
|
8
|
+
actions TEXT NOT NULL,
|
|
9
|
+
created_at INTEGER NOT NULL DEFAULT (unixepoch()),
|
|
10
|
+
updated_at INTEGER NOT NULL DEFAULT (unixepoch())
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
CREATE INDEX IF NOT EXISTS idx_automations_seed_slug ON automations(seed_slug);
|
|
14
|
+
CREATE INDEX IF NOT EXISTS idx_automations_enabled ON automations(enabled);
|