update db schema and reset db

pull/3/head
TZGyn 2 years ago
parent b3dc888bb3
commit c49faab6ae
Signed by: TZGyn
GPG Key ID: 122EAF77AE81FD4A

@ -1,3 +1,9 @@
CREATE TABLE IF NOT EXISTS "session" (
"token" varchar(255) NOT NULL,
"user_id" integer NOT NULL,
"expires" timestamp NOT NULL
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "shortener" ( CREATE TABLE IF NOT EXISTS "shortener" (
"id" serial PRIMARY KEY NOT NULL, "id" serial PRIMARY KEY NOT NULL,
"link" varchar(255) NOT NULL, "link" varchar(255) NOT NULL,
@ -7,11 +13,12 @@ CREATE TABLE IF NOT EXISTS "shortener" (
--> statement-breakpoint --> statement-breakpoint
CREATE TABLE IF NOT EXISTS "user" ( CREATE TABLE IF NOT EXISTS "user" (
"id" serial PRIMARY KEY NOT NULL, "id" serial PRIMARY KEY NOT NULL,
"uuid" text NOT NULL, "uuid" uuid DEFAULT gen_random_uuid(),
"email" varchar(255) NOT NULL, "email" varchar(255) NOT NULL,
"username" varchar(255) NOT NULL, "username" varchar(255),
"password" varchar(255) NOT NULL, "password" varchar(255) NOT NULL,
"created_at" timestamp DEFAULT now() NOT NULL "created_at" timestamp DEFAULT now() NOT NULL,
CONSTRAINT "user_email_unique" UNIQUE("email")
); );
--> statement-breakpoint --> statement-breakpoint
CREATE TABLE IF NOT EXISTS "visitor" ( CREATE TABLE IF NOT EXISTS "visitor" (

@ -1,7 +0,0 @@
CREATE TABLE IF NOT EXISTS "session" (
"token" varchar(255) NOT NULL,
"user_id" integer NOT NULL,
"expires" timestamp NOT NULL
);
--> statement-breakpoint
ALTER TABLE "user" ADD CONSTRAINT "user_email_unique" UNIQUE("email");

@ -1,9 +1,37 @@
{ {
"id": "1098bf22-b657-4c36-b85c-51f1a8f6e36d", "id": "9d44b46b-3e93-4782-8750-dbf39513bb0c",
"prevId": "00000000-0000-0000-0000-000000000000", "prevId": "00000000-0000-0000-0000-000000000000",
"version": "5", "version": "5",
"dialect": "pg", "dialect": "pg",
"tables": { "tables": {
"session": {
"name": "session",
"schema": "",
"columns": {
"token": {
"name": "token",
"type": "varchar(255)",
"primaryKey": false,
"notNull": true
},
"user_id": {
"name": "user_id",
"type": "integer",
"primaryKey": false,
"notNull": true
},
"expires": {
"name": "expires",
"type": "timestamp",
"primaryKey": false,
"notNull": true
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"shortener": { "shortener": {
"name": "shortener", "name": "shortener",
"schema": "", "schema": "",
@ -51,9 +79,10 @@
}, },
"uuid": { "uuid": {
"name": "uuid", "name": "uuid",
"type": "text", "type": "uuid",
"primaryKey": false, "primaryKey": false,
"notNull": true "notNull": false,
"default": "gen_random_uuid()"
}, },
"email": { "email": {
"name": "email", "name": "email",
@ -65,7 +94,7 @@
"name": "username", "name": "username",
"type": "varchar(255)", "type": "varchar(255)",
"primaryKey": false, "primaryKey": false,
"notNull": true "notNull": false
}, },
"password": { "password": {
"name": "password", "name": "password",
@ -84,7 +113,15 @@
"indexes": {}, "indexes": {},
"foreignKeys": {}, "foreignKeys": {},
"compositePrimaryKeys": {}, "compositePrimaryKeys": {},
"uniqueConstraints": {} "uniqueConstraints": {
"user_email_unique": {
"name": "user_email_unique",
"nullsNotDistinct": false,
"columns": [
"email"
]
}
}
}, },
"visitor": { "visitor": {
"name": "visitor", "name": "visitor",

@ -1,174 +0,0 @@
{
"id": "7c7bf598-99e4-405b-a089-065b8e8226fa",
"prevId": "1098bf22-b657-4c36-b85c-51f1a8f6e36d",
"version": "5",
"dialect": "pg",
"tables": {
"session": {
"name": "session",
"schema": "",
"columns": {
"token": {
"name": "token",
"type": "varchar(255)",
"primaryKey": false,
"notNull": true
},
"user_id": {
"name": "user_id",
"type": "integer",
"primaryKey": false,
"notNull": true
},
"expires": {
"name": "expires",
"type": "timestamp",
"primaryKey": false,
"notNull": true
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"shortener": {
"name": "shortener",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "serial",
"primaryKey": true,
"notNull": true
},
"link": {
"name": "link",
"type": "varchar(255)",
"primaryKey": false,
"notNull": true
},
"code": {
"name": "code",
"type": "varchar(255)",
"primaryKey": false,
"notNull": true
},
"created_at": {
"name": "created_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"user": {
"name": "user",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "serial",
"primaryKey": true,
"notNull": true
},
"uuid": {
"name": "uuid",
"type": "text",
"primaryKey": false,
"notNull": true
},
"email": {
"name": "email",
"type": "varchar(255)",
"primaryKey": false,
"notNull": true
},
"username": {
"name": "username",
"type": "varchar(255)",
"primaryKey": false,
"notNull": true
},
"password": {
"name": "password",
"type": "varchar(255)",
"primaryKey": false,
"notNull": true
},
"created_at": {
"name": "created_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {
"user_email_unique": {
"name": "user_email_unique",
"nullsNotDistinct": false,
"columns": [
"email"
]
}
}
},
"visitor": {
"name": "visitor",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "serial",
"primaryKey": true,
"notNull": true
},
"shortener_id": {
"name": "shortener_id",
"type": "integer",
"primaryKey": false,
"notNull": true
},
"created_at": {
"name": "created_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
},
"country_code": {
"name": "country_code",
"type": "varchar(255)",
"primaryKey": false,
"notNull": true
},
"country": {
"name": "country",
"type": "varchar(255)",
"primaryKey": false,
"notNull": true
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
}
},
"enums": {},
"schemas": {},
"_meta": {
"schemas": {},
"tables": {},
"columns": {}
}
}

@ -5,15 +5,8 @@
{ {
"idx": 0, "idx": 0,
"version": "5", "version": "5",
"when": 1699648628603, "when": 1699851315914,
"tag": "0000_bored_eddie_brock", "tag": "0000_nebulous_energizer",
"breakpoints": true
},
{
"idx": 1,
"version": "5",
"when": 1699649369484,
"tag": "0001_sudden_nightmare",
"breakpoints": true "breakpoints": true
} }
] ]

@ -3,8 +3,8 @@ import {
serial, serial,
varchar, varchar,
timestamp, timestamp,
text,
integer, integer,
uuid,
} from 'drizzle-orm/pg-core'; } from 'drizzle-orm/pg-core';
import { relations } from 'drizzle-orm'; import { relations } from 'drizzle-orm';
@ -18,9 +18,9 @@ export const shortener = pgTable('shortener', {
export const user = pgTable('user', { export const user = pgTable('user', {
id: serial('id').primaryKey().notNull(), id: serial('id').primaryKey().notNull(),
uuid: text('uuid').notNull(), uuid: uuid('uuid').defaultRandom(),
email: varchar('email', { length: 255 }).notNull().unique(), email: varchar('email', { length: 255 }).notNull().unique(),
username: varchar('username', { length: 255 }).notNull(), username: varchar('username', { length: 255 }),
password: varchar('password', { length: 255 }).notNull(), password: varchar('password', { length: 255 }).notNull(),
createdAt: timestamp('created_at', { mode: 'string' }).defaultNow().notNull(), createdAt: timestamp('created_at', { mode: 'string' }).defaultNow().notNull(),
}); });

Loading…
Cancel
Save