Skip to content
This repository has been archived by the owner on Sep 9, 2024. It is now read-only.

Commit

Permalink
feat: upvote fix
Browse files Browse the repository at this point in the history
  • Loading branch information
KunalSin9h committed May 28, 2024
1 parent 56f2e9f commit 59b07e3
Show file tree
Hide file tree
Showing 10 changed files with 625 additions and 84 deletions.
19 changes: 17 additions & 2 deletions db/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ export const links = pgTable("links", {
userID: uuid("user_id")
.references(() => users.id)
.notNull(),
views: integer("views").default(1).notNull(),
votes: integer("votes").default(1).notNull(),
userName: text("user_name").notNull(),
views: integer("views").default(0).notNull(),
votes: integer("votes").default(0).notNull(),
createdAt: timestamp("created_at", {
withTimezone: true,
}).notNull(),
Expand All @@ -51,6 +52,20 @@ export const links = pgTable("links", {
}).notNull(),
});

export const userUpvoteLink = pgTable("user_upvote_link", {
userID: uuid("user_id")
.references(() => users.id)
.notNull(),

linkID: uuid("link_id")
.references(() => links.id)
.notNull(),

createdAt: timestamp("created_at", {
withTimezone: true,
}).notNull(),
});

export type UserType = typeof users.$inferInsert;
export type UserTypeSelect = typeof users.$inferInsert;
export type LinkType = typeof links.$inferInsert;
Expand Down
17 changes: 17 additions & 0 deletions drizzle/0002_low_sinister_six.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
CREATE TABLE IF NOT EXISTS "user_upvote_link" (
"user_id" uuid NOT NULL,
"link_id" uuid NOT NULL,
"created_at" timestamp with time zone NOT NULL
);
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "user_upvote_link" ADD CONSTRAINT "user_upvote_link_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "user_upvote_link" ADD CONSTRAINT "user_upvote_link_link_id_links_id_fk" FOREIGN KEY ("link_id") REFERENCES "public"."links"("id") ON DELETE no action ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
3 changes: 3 additions & 0 deletions drizzle/0003_massive_hydra.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ALTER TABLE "links" ALTER COLUMN "views" SET DEFAULT 0;--> statement-breakpoint
ALTER TABLE "links" ALTER COLUMN "votes" SET DEFAULT 0;--> statement-breakpoint
ALTER TABLE "links" ADD COLUMN "user_name" text DEFAULT '' NOT NULL;
219 changes: 219 additions & 0 deletions drizzle/meta/0002_snapshot.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
{
"id": "f5b8df06-1ea7-4ac5-b2c8-5decd3b885b0",
"prevId": "2f5e53ae-4268-495e-b5bf-3fb2cfc09163",
"version": "6",
"dialect": "postgresql",
"tables": {
"public.links": {
"name": "links",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "uuid",
"primaryKey": true,
"notNull": true
},
"url": {
"name": "url",
"type": "text",
"primaryKey": false,
"notNull": true
},
"title": {
"name": "title",
"type": "text",
"primaryKey": false,
"notNull": true
},
"host": {
"name": "host",
"type": "varchar(325)",
"primaryKey": false,
"notNull": true
},
"user_id": {
"name": "user_id",
"type": "uuid",
"primaryKey": false,
"notNull": true
},
"views": {
"name": "views",
"type": "integer",
"primaryKey": false,
"notNull": true,
"default": 1
},
"votes": {
"name": "votes",
"type": "integer",
"primaryKey": false,
"notNull": true,
"default": 1
},
"created_at": {
"name": "created_at",
"type": "timestamp with time zone",
"primaryKey": false,
"notNull": true
},
"updated_at": {
"name": "updated_at",
"type": "timestamp with time zone",
"primaryKey": false,
"notNull": true
}
},
"indexes": {},
"foreignKeys": {
"links_user_id_users_id_fk": {
"name": "links_user_id_users_id_fk",
"tableFrom": "links",
"tableTo": "users",
"columnsFrom": [
"user_id"
],
"columnsTo": [
"id"
],
"onDelete": "no action",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"public.user_upvote_link": {
"name": "user_upvote_link",
"schema": "",
"columns": {
"user_id": {
"name": "user_id",
"type": "uuid",
"primaryKey": false,
"notNull": true
},
"link_id": {
"name": "link_id",
"type": "uuid",
"primaryKey": false,
"notNull": true
},
"created_at": {
"name": "created_at",
"type": "timestamp with time zone",
"primaryKey": false,
"notNull": true
}
},
"indexes": {},
"foreignKeys": {
"user_upvote_link_user_id_users_id_fk": {
"name": "user_upvote_link_user_id_users_id_fk",
"tableFrom": "user_upvote_link",
"tableTo": "users",
"columnsFrom": [
"user_id"
],
"columnsTo": [
"id"
],
"onDelete": "no action",
"onUpdate": "no action"
},
"user_upvote_link_link_id_links_id_fk": {
"name": "user_upvote_link_link_id_links_id_fk",
"tableFrom": "user_upvote_link",
"tableTo": "links",
"columnsFrom": [
"link_id"
],
"columnsTo": [
"id"
],
"onDelete": "no action",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"public.users": {
"name": "users",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "uuid",
"primaryKey": true,
"notNull": true
},
"frist_name": {
"name": "frist_name",
"type": "varchar(256)",
"primaryKey": false,
"notNull": true
},
"last_name": {
"name": "last_name",
"type": "varchar(256)",
"primaryKey": false,
"notNull": false
},
"email": {
"name": "email",
"type": "varchar(256)",
"primaryKey": false,
"notNull": true
},
"image": {
"name": "image",
"type": "varchar(256)",
"primaryKey": false,
"notNull": true
},
"created_at": {
"name": "created_at",
"type": "timestamp with time zone",
"primaryKey": false,
"notNull": true
},
"updated_at": {
"name": "updated_at",
"type": "timestamp with time zone",
"primaryKey": false,
"notNull": true
}
},
"indexes": {
"email_index": {
"name": "email_index",
"columns": [
"email"
],
"isUnique": true
}
},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
}
},
"enums": {
"public.categories": {
"name": "categories",
"schema": "public",
"values": [
"manufacturing",
"research"
]
}
},
"schemas": {},
"_meta": {
"columns": {},
"schemas": {},
"tables": {}
}
}
Loading

0 comments on commit 59b07e3

Please sign in to comment.