diff --git a/.drizzle/0002_mature_doorman.sql b/.drizzle/0002_mature_doorman.sql new file mode 100644 index 0000000..956227f --- /dev/null +++ b/.drizzle/0002_mature_doorman.sql @@ -0,0 +1,2 @@ +ALTER TABLE "posts" ALTER COLUMN "excerpt" SET NOT NULL;--> statement-breakpoint +ALTER TABLE "posts" ADD COLUMN "draft" boolean DEFAULT true NOT NULL; \ No newline at end of file diff --git a/.drizzle/0003_perfect_chimera.sql b/.drizzle/0003_perfect_chimera.sql new file mode 100644 index 0000000..0cb0ac1 --- /dev/null +++ b/.drizzle/0003_perfect_chimera.sql @@ -0,0 +1,12 @@ +ALTER TABLE "comments" DROP CONSTRAINT "comments_post_id_posts_id_fk"; +--> statement-breakpoint +ALTER TABLE "comments" DROP CONSTRAINT "comments_parent_id_comments_id_fk"; +--> statement-breakpoint +ALTER TABLE "comments" DROP CONSTRAINT "comments_author_id_users_id_fk"; +--> statement-breakpoint +ALTER TABLE "posts" DROP CONSTRAINT "posts_author_id_users_id_fk"; +--> statement-breakpoint +ALTER TABLE "comments" ADD CONSTRAINT "comments_post_id_posts_id_fk" FOREIGN KEY ("post_id") REFERENCES "public"."posts"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE "comments" ADD CONSTRAINT "comments_parent_id_comments_id_fk" FOREIGN KEY ("parent_id") REFERENCES "public"."comments"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE "comments" ADD CONSTRAINT "comments_author_id_users_id_fk" FOREIGN KEY ("author_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE "posts" ADD CONSTRAINT "posts_author_id_users_id_fk" FOREIGN KEY ("author_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action; \ No newline at end of file diff --git a/.drizzle/meta/0002_snapshot.json b/.drizzle/meta/0002_snapshot.json new file mode 100644 index 0000000..86d275c --- /dev/null +++ b/.drizzle/meta/0002_snapshot.json @@ -0,0 +1,278 @@ +{ + "id": "2aa4066a-c421-4e1e-a587-c0d6332470fd", + "prevId": "2cbd9483-c81e-45f3-8892-b9539e29f8c1", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.comments": { + "name": "comments", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigint", + "primaryKey": true, + "notNull": true + }, + "post_id": { + "name": "post_id", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "parent_id": { + "name": "parent_id", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "author_id": { + "name": "author_id", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "display_name": { + "name": "display_name", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "content": { + "name": "content", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "comments_post_id_posts_id_fk": { + "name": "comments_post_id_posts_id_fk", + "tableFrom": "comments", + "tableTo": "posts", + "columnsFrom": [ + "post_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "comments_parent_id_comments_id_fk": { + "name": "comments_parent_id_comments_id_fk", + "tableFrom": "comments", + "tableTo": "comments", + "columnsFrom": [ + "parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "comments_author_id_users_id_fk": { + "name": "comments_author_id_users_id_fk", + "tableFrom": "comments", + "tableTo": "users", + "columnsFrom": [ + "author_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.posts": { + "name": "posts", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigint", + "primaryKey": true, + "notNull": true + }, + "author_id": { + "name": "author_id", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "slug": { + "name": "slug", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true + }, + "title": { + "name": "title", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "excerpt": { + "name": "excerpt", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "content": { + "name": "content", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "draft": { + "name": "draft", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "published_at": { + "name": "published_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "posts_author_id_users_id_fk": { + "name": "posts_author_id_users_id_fk", + "tableFrom": "posts", + "tableTo": "users", + "columnsFrom": [ + "author_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "posts_slug_unique": { + "name": "posts_slug_unique", + "nullsNotDistinct": false, + "columns": [ + "slug" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.users": { + "name": "users", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigint", + "primaryKey": true, + "notNull": true + }, + "username": { + "name": "username", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true + }, + "display_name": { + "name": "display_name", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "email": { + "name": "email", + "type": "varchar(320)", + "primaryKey": false, + "notNull": true + }, + "password": { + "name": "password", + "type": "varchar(72)", + "primaryKey": false, + "notNull": true + }, + "avatar": { + "name": "avatar", + "type": "varchar(40)", + "primaryKey": false, + "notNull": false + }, + "permissions": { + "name": "permissions", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "users_username_unique": { + "name": "users_username_unique", + "nullsNotDistinct": false, + "columns": [ + "username" + ] + }, + "users_email_unique": { + "name": "users_email_unique", + "nullsNotDistinct": false, + "columns": [ + "email" + ] + }, + "users_password_unique": { + "name": "users_password_unique", + "nullsNotDistinct": false, + "columns": [ + "password" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + } + }, + "enums": {}, + "schemas": {}, + "sequences": {}, + "roles": {}, + "policies": {}, + "views": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} \ No newline at end of file diff --git a/.drizzle/meta/0003_snapshot.json b/.drizzle/meta/0003_snapshot.json new file mode 100644 index 0000000..60fa7ad --- /dev/null +++ b/.drizzle/meta/0003_snapshot.json @@ -0,0 +1,278 @@ +{ + "id": "d4271530-af67-49ae-a6df-f87645ab4cc5", + "prevId": "2aa4066a-c421-4e1e-a587-c0d6332470fd", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.comments": { + "name": "comments", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigint", + "primaryKey": true, + "notNull": true + }, + "post_id": { + "name": "post_id", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "parent_id": { + "name": "parent_id", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "author_id": { + "name": "author_id", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "display_name": { + "name": "display_name", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "content": { + "name": "content", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "comments_post_id_posts_id_fk": { + "name": "comments_post_id_posts_id_fk", + "tableFrom": "comments", + "tableTo": "posts", + "columnsFrom": [ + "post_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "comments_parent_id_comments_id_fk": { + "name": "comments_parent_id_comments_id_fk", + "tableFrom": "comments", + "tableTo": "comments", + "columnsFrom": [ + "parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "comments_author_id_users_id_fk": { + "name": "comments_author_id_users_id_fk", + "tableFrom": "comments", + "tableTo": "users", + "columnsFrom": [ + "author_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.posts": { + "name": "posts", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigint", + "primaryKey": true, + "notNull": true + }, + "author_id": { + "name": "author_id", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "slug": { + "name": "slug", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true + }, + "title": { + "name": "title", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "excerpt": { + "name": "excerpt", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "content": { + "name": "content", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "draft": { + "name": "draft", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "published_at": { + "name": "published_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "posts_author_id_users_id_fk": { + "name": "posts_author_id_users_id_fk", + "tableFrom": "posts", + "tableTo": "users", + "columnsFrom": [ + "author_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "posts_slug_unique": { + "name": "posts_slug_unique", + "nullsNotDistinct": false, + "columns": [ + "slug" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.users": { + "name": "users", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigint", + "primaryKey": true, + "notNull": true + }, + "username": { + "name": "username", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true + }, + "display_name": { + "name": "display_name", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "email": { + "name": "email", + "type": "varchar(320)", + "primaryKey": false, + "notNull": true + }, + "password": { + "name": "password", + "type": "varchar(72)", + "primaryKey": false, + "notNull": true + }, + "avatar": { + "name": "avatar", + "type": "varchar(40)", + "primaryKey": false, + "notNull": false + }, + "permissions": { + "name": "permissions", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "users_username_unique": { + "name": "users_username_unique", + "nullsNotDistinct": false, + "columns": [ + "username" + ] + }, + "users_email_unique": { + "name": "users_email_unique", + "nullsNotDistinct": false, + "columns": [ + "email" + ] + }, + "users_password_unique": { + "name": "users_password_unique", + "nullsNotDistinct": false, + "columns": [ + "password" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + } + }, + "enums": {}, + "schemas": {}, + "sequences": {}, + "roles": {}, + "policies": {}, + "views": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} \ No newline at end of file diff --git a/.drizzle/meta/_journal.json b/.drizzle/meta/_journal.json index 48cd32a..c9cec1b 100644 --- a/.drizzle/meta/_journal.json +++ b/.drizzle/meta/_journal.json @@ -15,6 +15,20 @@ "when": 1774691481484, "tag": "0001_late_agent_zero", "breakpoints": true + }, + { + "idx": 2, + "version": "7", + "when": 1774712783794, + "tag": "0002_mature_doorman", + "breakpoints": true + }, + { + "idx": 3, + "version": "7", + "when": 1774713093687, + "tag": "0003_perfect_chimera", + "breakpoints": true } ] } \ No newline at end of file diff --git a/.drizzle/relations.ts b/.drizzle/relations.ts index 21fafbc..7745f87 100644 --- a/.drizzle/relations.ts +++ b/.drizzle/relations.ts @@ -1,18 +1,5 @@ import { relations } from "drizzle-orm/relations"; -import { users, posts, comments } from "./schema"; - -export const postsRelations = relations(posts, ({one, many}) => ({ - user: one(users, { - fields: [posts.authorId], - references: [users.id] - }), - comments: many(comments), -})); - -export const usersRelations = relations(users, ({many}) => ({ - posts: many(posts), - comments: many(comments), -})); +import { posts, comments, users } from "./schema"; export const commentsRelations = relations(comments, ({one, many}) => ({ post: one(posts, { @@ -31,4 +18,17 @@ export const commentsRelations = relations(comments, ({one, many}) => ({ fields: [comments.authorId], references: [users.id] }), +})); + +export const postsRelations = relations(posts, ({one, many}) => ({ + comments: many(comments), + user: one(users, { + fields: [posts.authorId], + references: [users.id] + }), +})); + +export const usersRelations = relations(users, ({many}) => ({ + comments: many(comments), + posts: many(posts), })); \ No newline at end of file diff --git a/.drizzle/schema.ts b/.drizzle/schema.ts index 7239721..319b670 100644 --- a/.drizzle/schema.ts +++ b/.drizzle/schema.ts @@ -1,27 +1,8 @@ -import { pgTable, foreignKey, unique, bigint, varchar, text, timestamp, integer } from "drizzle-orm/pg-core" +import { pgTable, foreignKey, bigint, varchar, text, unique, integer, timestamp, boolean } from "drizzle-orm/pg-core" import { sql } from "drizzle-orm" -export const posts = pgTable("posts", { - // You can use { mode: "bigint" } if numbers are exceeding js number limitations - id: bigint({ mode: "number" }).primaryKey().notNull(), - // You can use { mode: "bigint" } if numbers are exceeding js number limitations - authorId: bigint("author_id", { mode: "number" }), - slug: varchar({ length: 128 }).notNull(), - title: varchar({ length: 256 }).notNull(), - content: text().notNull(), - publishedAt: timestamp("published_at", { mode: 'string' }).defaultNow().notNull(), - updatedAt: timestamp("updated_at", { mode: 'string' }).defaultNow().notNull(), -}, (table) => [ - foreignKey({ - columns: [table.authorId], - foreignColumns: [users.id], - name: "posts_author_id_users_id_fk" - }), - unique("posts_slug_unique").on(table.slug), -]); - export const comments = pgTable("comments", { // You can use { mode: "bigint" } if numbers are exceeding js number limitations id: bigint({ mode: "number" }).primaryKey().notNull(), @@ -38,17 +19,17 @@ export const comments = pgTable("comments", { columns: [table.postId], foreignColumns: [posts.id], name: "comments_post_id_posts_id_fk" - }), + }).onDelete("cascade"), foreignKey({ columns: [table.parentId], foreignColumns: [table.id], name: "comments_parent_id_comments_id_fk" - }), + }).onDelete("cascade"), foreignKey({ columns: [table.authorId], foreignColumns: [users.id], name: "comments_author_id_users_id_fk" - }), + }).onDelete("cascade"), ]); export const users = pgTable("users", { @@ -65,3 +46,24 @@ export const users = pgTable("users", { unique("users_email_unique").on(table.email), unique("users_password_unique").on(table.password), ]); + +export const posts = pgTable("posts", { + // You can use { mode: "bigint" } if numbers are exceeding js number limitations + id: bigint({ mode: "number" }).primaryKey().notNull(), + // You can use { mode: "bigint" } if numbers are exceeding js number limitations + authorId: bigint("author_id", { mode: "number" }), + slug: varchar({ length: 128 }).notNull(), + title: varchar({ length: 256 }).notNull(), + content: text().notNull(), + publishedAt: timestamp("published_at", { mode: 'string' }).defaultNow().notNull(), + updatedAt: timestamp("updated_at", { mode: 'string' }).defaultNow().notNull(), + excerpt: text().notNull(), + draft: boolean().default(true).notNull(), +}, (table) => [ + foreignKey({ + columns: [table.authorId], + foreignColumns: [users.id], + name: "posts_author_id_users_id_fk" + }).onDelete("cascade"), + unique("posts_slug_unique").on(table.slug), +]); diff --git a/app/(admin)/admin/art/page.tsx b/app/(admin)/admin/art/page.tsx new file mode 100644 index 0000000..a9479ec --- /dev/null +++ b/app/(admin)/admin/art/page.tsx @@ -0,0 +1,15 @@ +import type { Metadata } from 'next'; + +export const metadata: Metadata = { + title: 'Admin > Art' +}; + +export default function Art() { + return ( + <> +
Admin {'>'} Art
+ +Admin {'>'} Comments
+ +Admin {'>'} Photos
+ +Admin {'>'} Posts
+ +| + | Slug | +Title | +Excerpt | +Draft | +Published | +Updated | +Actions | +
|---|---|---|---|---|---|---|---|
| {p.id} | +{p.slug} | +{p.title} | +{p.excerpt} | ++ + | +{p.publishedAt.toLocaleString('hu-HU')} | +{p.updatedAt.toLocaleString('hu-HU')} | ++ + + + | +