diff --git a/docker/postgres.Dockerfile b/docker/postgres.Dockerfile index 4caffc2..b2075fc 100644 --- a/docker/postgres.Dockerfile +++ b/docker/postgres.Dockerfile @@ -1,3 +1,4 @@ FROM postgres:16 -COPY ./docker/initdb.d/ /docker-entrypoint-initdb.d/ \ No newline at end of file +COPY ./docker/initdb.d/ /docker-entrypoint-initdb.d/ +# COPY ./docker/postgres.conf /var/lib/postgresql/data/postgresql.conf diff --git a/docker/postgres.conf b/docker/postgres.conf new file mode 100644 index 0000000..e69de29 diff --git a/src/lib/server/database/init_db.ts b/src/lib/server/database/init_db.ts index 6b60287..5c97029 100644 --- a/src/lib/server/database/init_db.ts +++ b/src/lib/server/database/init_db.ts @@ -10,7 +10,8 @@ export default async function init() { { name: 'article', columns: [ - { name: 'id', type: 'serial', constraint: 'primary key' }, + { name: 'seq', type: 'serial', constraint: 'primary key' }, + { name: 'id', type: 'text', constraint: 'not null' }, { name: 'title', type: 'text', constraint: 'not null' }, { name: 'released_at', type: 'timestamp', constraint: 'not null' }, { name: 'updated_at', type: 'timestamp', constraint: 'not null' }, @@ -18,13 +19,53 @@ export default async function init() { { name: 'content', type: 'text', constraint: 'not null' }, ], }, + { + name: 'article_comment', + columns: [ + { name: 'id', type: 'serial', constraint: 'primary key' }, + { name: 'article', type: 'integer', constraint: 'not null' }, + { name: 'posted_at', type: 'timestamp', constraint: 'not null' }, + { name: 'content', type: 'text', constraint: 'not null' }, + ], + }, + { + name: 'thread', + columns: [ + { name: 'seq', type: 'serial', constraint: 'primary key' }, + { name: 'id', type: 'text', constraint: 'not null' }, + { name: 'title', type: 'text', constraint: 'not null' }, + { name: 'created_at', type: 'timestamp', constraint: 'not null' }, + { name: 'updated_at', type: 'timestamp', constraint: 'not null' }, + { name: 'tags', type: 'text[]', constraint: 'not null' }, + { name: 'content', type: 'text', constraint: 'not null' }, + ], + }, + { + name: 'thread_post', + columns: [ + { name: 'seq', type: 'serial', constraint: 'primary key' }, + { name: 'thread_id', type: 'integer', constraint: 'not null' }, + { name: 'title', type: 'text', constraint: 'not null' }, + { name: 'posted_at', type: 'timestamp', constraint: 'not null' }, + { name: 'content', type: 'text', constraint: 'not null' }, + ], + }, + { + name: 'thread_comment', + columns: [ + { name: 'id', type: 'serial', constraint: 'primary key' }, + { name: 'thread', type: 'integer', constraint: 'not null' }, + { name: 'posted_at', type: 'timestamp', constraint: 'not null' }, + { name: 'content', type: 'text', constraint: 'not null' }, + ], + } ]; const db = await PG(); try { await db.begin(); for (const schema of schemas) { const res = await db.query(`select * from information_schema.tables where table_name = '${schema.name}'`) - if (res.rowCount === null) { + if (res.rowCount == 0) { console.log(`Creating table ${schema.name}`); const columnStr = schema.columns.map(c => `${c.name} ${c.type} ${c.constraint}`).join(', '); await db.query(`create table ${schema.name} (${columnStr})`);