Skip to content

Commit

Permalink
refactor: make columns unique
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianLThomas committed Mar 19, 2024
1 parent 9b96638 commit d6758c5
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 13 deletions.
8 changes: 8 additions & 0 deletions drizzle/0000_handy_bishop.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CREATE TABLE `urls` (
`id` integer PRIMARY KEY NOT NULL,
`short` text NOT NULL,
`long` text NOT NULL
);
--> statement-breakpoint
CREATE UNIQUE INDEX `urls_short_unique` ON `urls` (`short`);--> statement-breakpoint
CREATE UNIQUE INDEX `urls_long_unique` ON `urls` (`long`);
5 changes: 0 additions & 5 deletions drizzle/0000_nervous_satana.sql

This file was deleted.

19 changes: 17 additions & 2 deletions drizzle/meta/0000_snapshot.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"version": "5",
"dialect": "sqlite",
"id": "c7d4fd2e-7fb1-4d63-994b-df46a1bed9b0",
"id": "2faa6e6e-6e40-4b2d-bb17-7fcd34216875",
"prevId": "00000000-0000-0000-0000-000000000000",
"tables": {
"urls": {
Expand Down Expand Up @@ -29,7 +29,22 @@
"autoincrement": false
}
},
"indexes": {},
"indexes": {
"urls_short_unique": {
"name": "urls_short_unique",
"columns": [
"short"
],
"isUnique": true
},
"urls_long_unique": {
"name": "urls_long_unique",
"columns": [
"long"
],
"isUnique": true
}
},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
Expand Down
4 changes: 2 additions & 2 deletions drizzle/meta/_journal.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
{
"idx": 0,
"version": "5",
"when": 1710347878065,
"tag": "0000_nervous_satana",
"when": 1710855367595,
"tag": "0000_handy_bishop",
"breakpoints": true
}
]
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"dev": "wrangler dev",
"start": "wrangler dev",
"db:query": " npx wrangler d1 execute url-shortener --local --command='SELECT * FROM urls'",
"db:init": "npx wrangler d1 execute url-shortener --local --file=./drizzle/0000_nervous_satana.sql",
"db:generate": "drizzle-kit generate:sqlite --schema=src/schema.ts",
"db:init": "npx wrangler d1 execute url-shortener --local --file=./drizzle/0000_handy_bishop.sql",
"db:generate": "drizzle-kit generate:sqlite --schema=src/db/schema.ts",
"test": "npm run test:unit && npm run test:integration",
"test:unit": "jest --runInBand **/*.spec.ts",
"test:integration": "jest --runInBand test/**/*.test.ts",
Expand Down
4 changes: 2 additions & 2 deletions src/db/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import { integer, sqliteTable, text } from 'drizzle-orm/sqlite-core';

export const urls = sqliteTable('urls', {
id: integer('id').primaryKey(),
short: text('short').notNull(),
long: text('long').notNull(),
short: text('short').notNull().unique(),
long: text('long').notNull().unique(),
});

0 comments on commit d6758c5

Please sign in to comment.