PostgreSQL 데이터 계층 추가

This commit is contained in:
2026-04-29 15:22:54 +09:00
parent cbf5ed6c8c
commit 5ee6fcd54b
20 changed files with 429 additions and 34 deletions

View File

@@ -0,0 +1,47 @@
CREATE EXTENSION IF NOT EXISTS pgcrypto;
CREATE TABLE IF NOT EXISTS posts (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
title TEXT NOT NULL,
slug TEXT NOT NULL UNIQUE,
content TEXT NOT NULL DEFAULT '',
excerpt TEXT NOT NULL DEFAULT '',
featured_image TEXT,
status TEXT NOT NULL DEFAULT 'draft',
published_at TIMESTAMPTZ,
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
CONSTRAINT posts_status_check CHECK (status IN ('published', 'draft', 'private'))
);
CREATE INDEX IF NOT EXISTS posts_status_published_at_idx
ON posts (status, published_at DESC);
CREATE TABLE IF NOT EXISTS pages (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
title TEXT NOT NULL,
slug TEXT NOT NULL UNIQUE,
content TEXT NOT NULL DEFAULT '',
featured_image TEXT,
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
CREATE TABLE IF NOT EXISTS tags (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
name TEXT NOT NULL,
slug TEXT NOT NULL UNIQUE,
description TEXT NOT NULL DEFAULT '',
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
CREATE TABLE IF NOT EXISTS post_tags (
post_id UUID NOT NULL REFERENCES posts(id) ON DELETE CASCADE,
tag_id UUID NOT NULL REFERENCES tags(id) ON DELETE CASCADE,
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
PRIMARY KEY (post_id, tag_id)
);
CREATE INDEX IF NOT EXISTS post_tags_tag_id_idx
ON post_tags (tag_id);

View File

@@ -0,0 +1,65 @@
INSERT INTO tags (id, name, slug, description)
VALUES
('44444444-4444-4444-8444-444444444444', 'NOTE', 'note', '생각과 기록을 모아두는 태그입니다.'),
('55555555-5555-4555-8555-555555555555', 'DEV', 'dev', '개발과 제작 과정을 기록하는 태그입니다.')
ON CONFLICT (slug) DO NOTHING;
INSERT INTO posts (
id,
title,
slug,
content,
excerpt,
status,
published_at,
created_at,
updated_at
)
VALUES
(
'11111111-1111-4111-8111-111111111111',
'sori.studio를 직접 만들기 시작하며',
'hello-sori-studio',
'개인 블로그와 포털 역할을 한 공간에 담기 위한 첫 글입니다.',
'블로그와 포털의 경계에 있는 개인 공간을 직접 구축하기 위한 첫 기록입니다.',
'published',
'2026-04-29T00:00:00.000Z',
'2026-04-29T00:00:00.000Z',
'2026-04-29T00:00:00.000Z'
),
(
'22222222-2222-4222-8222-222222222222',
'글쓰기 도구는 왜 직접 만들게 되는가',
'custom-writing-tool',
'기존 도구를 거치며 남은 취향의 빈칸을 직접 채우는 과정입니다.',
'네이버 블로그, 티스토리, 워드프레스, Ghost를 거쳐 남은 취향의 빈칸을 정리합니다.',
'published',
'2026-04-29T00:00:00.000Z',
'2026-04-29T00:00:00.000Z',
'2026-04-29T00:00:00.000Z'
)
ON CONFLICT (slug) DO NOTHING;
INSERT INTO post_tags (post_id, tag_id)
VALUES
('11111111-1111-4111-8111-111111111111', '44444444-4444-4444-8444-444444444444'),
('22222222-2222-4222-8222-222222222222', '55555555-5555-4555-8555-555555555555')
ON CONFLICT (post_id, tag_id) DO NOTHING;
INSERT INTO pages (
id,
title,
slug,
content,
created_at,
updated_at
)
VALUES (
'33333333-3333-4333-8333-333333333333',
'About',
'about',
'sori.studio 소개 페이지입니다.',
'2026-04-29T00:00:00.000Z',
'2026-04-29T00:00:00.000Z'
)
ON CONFLICT (slug) DO NOTHING;