feat: initial zeropost-engine structure

- AI service with Anthropic claude-sonnet-4-6
- Bull queue for async generation jobs
- Routes: /api/generate, /api/channels, /api/posts
- PostgreSQL schema: users, channels, posts, generation_jobs
- Supports: post, article, topics generation types
This commit is contained in:
Alexey Pavlov
2026-05-30 21:29:00 +03:00
parent 1b9767f269
commit 612053b93d
12 changed files with 1907 additions and 0 deletions
+67
View File
@@ -0,0 +1,67 @@
const { Pool } = require('pg');
const config = require('../config');
const pool = new Pool(config.db);
pool.on('error', (err) => {
console.error('[DB] Unexpected error on idle client', err);
});
const query = (text, params) => pool.query(text, params);
const migrate = async () => {
await query(`
CREATE TABLE IF NOT EXISTS generation_jobs (
id SERIAL PRIMARY KEY,
type VARCHAR(50) NOT NULL, -- 'article', 'post', 'caption'
channel_id INTEGER,
topic TEXT,
prompt TEXT,
result TEXT,
status VARCHAR(20) DEFAULT 'pending', -- pending, processing, done, failed
error TEXT,
metadata JSONB DEFAULT '{}',
created_at TIMESTAMPTZ DEFAULT NOW(),
updated_at TIMESTAMPTZ DEFAULT NOW()
);
CREATE TABLE IF NOT EXISTS channels (
id SERIAL PRIMARY KEY,
user_id INTEGER NOT NULL,
name VARCHAR(255) NOT NULL,
tg_channel_id VARCHAR(255),
bot_token TEXT,
topic TEXT,
tone VARCHAR(100) DEFAULT 'neutral',
language VARCHAR(10) DEFAULT 'ru',
post_schedule JSONB DEFAULT '{}',
is_active BOOLEAN DEFAULT true,
created_at TIMESTAMPTZ DEFAULT NOW()
);
CREATE TABLE IF NOT EXISTS users (
id SERIAL PRIMARY KEY,
email VARCHAR(255) UNIQUE NOT NULL,
password TEXT NOT NULL,
plan VARCHAR(20) DEFAULT 'free', -- free, pro, enterprise
api_key VARCHAR(64) UNIQUE,
created_at TIMESTAMPTZ DEFAULT NOW()
);
CREATE TABLE IF NOT EXISTS posts (
id SERIAL PRIMARY KEY,
channel_id INTEGER REFERENCES channels(id),
job_id INTEGER REFERENCES generation_jobs(id),
content TEXT NOT NULL,
status VARCHAR(20) DEFAULT 'draft', -- draft, scheduled, published, failed
scheduled_at TIMESTAMPTZ,
published_at TIMESTAMPTZ,
tg_message_id BIGINT,
metadata JSONB DEFAULT '{}',
created_at TIMESTAMPTZ DEFAULT NOW()
);
`);
console.log('[DB] Migrations applied');
};
module.exports = { query, migrate };