mirror of
				https://github.com/zws-im/zws.git
				synced 2025-10-30 23:27:52 +02:00 
			
		
		
		
	feat(api): simplify indexes in migrations
This commit is contained in:
		| @@ -9,21 +9,12 @@ export const blockedHostnames = pgTable('blocked_hostnames', { | ||||
| // It will just ignore it and use the default (BTREE) every time | ||||
| // At some point they will fix this, and trying to create a migration will suddenly include those index changes | ||||
|  | ||||
| export const urls = pgTable( | ||||
| 	'urls', | ||||
| 	{ | ||||
| 		blocked: boolean('blocked').default(false).notNull(), | ||||
| 		createdAt: timestamp('created_at', { withTimezone: true }).defaultNow().notNull(), | ||||
| 		shortBase64: text('short_base64').notNull().primaryKey(), | ||||
| 		url: text('url').notNull(), | ||||
| 	}, | ||||
| 	(urls) => ({ | ||||
| 		// prettier-ignore | ||||
| 		blockedIdx: index().using('hash', urls.blocked), | ||||
| 		// prettier-ignore | ||||
| 		urlIdx: index().using('hash', urls.url), | ||||
| 	}), | ||||
| ); | ||||
| export const urls = pgTable('urls', { | ||||
| 	blocked: boolean('blocked').default(false).notNull(), | ||||
| 	createdAt: timestamp('created_at', { withTimezone: true }).defaultNow().notNull(), | ||||
| 	shortBase64: text('short_base64').notNull().primaryKey(), | ||||
| 	url: text('url').notNull(), | ||||
| }); | ||||
|  | ||||
| export const visits = pgTable( | ||||
| 	'visits', | ||||
|   | ||||
							
								
								
									
										2
									
								
								drizzle/0002_complex_pretty_boy.sql
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								drizzle/0002_complex_pretty_boy.sql
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,2 @@ | ||||
| CREATE INDEX IF NOT EXISTS "visits_url_short_base64_index" ON "visits" USING hash (url_short_base64);--> statement-breakpoint | ||||
| CREATE INDEX IF NOT EXISTS "visits_timestamp_index" ON "visits" USING btree (timestamp); | ||||
							
								
								
									
										144
									
								
								drizzle/meta/0002_snapshot.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										144
									
								
								drizzle/meta/0002_snapshot.json
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,144 @@ | ||||
| { | ||||
| 	"id": "eb9c04b4-5826-4932-9d34-5cd9cc0d8cfb", | ||||
| 	"prevId": "5e370c82-32f6-4b3a-9027-8cd493a75f34", | ||||
| 	"version": "7", | ||||
| 	"dialect": "postgresql", | ||||
| 	"tables": { | ||||
| 		"public.blocked_hostnames": { | ||||
| 			"name": "blocked_hostnames", | ||||
| 			"schema": "", | ||||
| 			"columns": { | ||||
| 				"hostname": { | ||||
| 					"name": "hostname", | ||||
| 					"type": "text", | ||||
| 					"primaryKey": true, | ||||
| 					"notNull": true | ||||
| 				}, | ||||
| 				"created_at": { | ||||
| 					"name": "created_at", | ||||
| 					"type": "timestamp with time zone", | ||||
| 					"primaryKey": false, | ||||
| 					"notNull": true, | ||||
| 					"default": "now()" | ||||
| 				} | ||||
| 			}, | ||||
| 			"indexes": {}, | ||||
| 			"foreignKeys": {}, | ||||
| 			"compositePrimaryKeys": {}, | ||||
| 			"uniqueConstraints": {} | ||||
| 		}, | ||||
| 		"public.urls": { | ||||
| 			"name": "urls", | ||||
| 			"schema": "", | ||||
| 			"columns": { | ||||
| 				"blocked": { | ||||
| 					"name": "blocked", | ||||
| 					"type": "boolean", | ||||
| 					"primaryKey": false, | ||||
| 					"notNull": true, | ||||
| 					"default": false | ||||
| 				}, | ||||
| 				"created_at": { | ||||
| 					"name": "created_at", | ||||
| 					"type": "timestamp with time zone", | ||||
| 					"primaryKey": false, | ||||
| 					"notNull": true, | ||||
| 					"default": "now()" | ||||
| 				}, | ||||
| 				"short_base64": { | ||||
| 					"name": "short_base64", | ||||
| 					"type": "text", | ||||
| 					"primaryKey": true, | ||||
| 					"notNull": true | ||||
| 				}, | ||||
| 				"url": { | ||||
| 					"name": "url", | ||||
| 					"type": "text", | ||||
| 					"primaryKey": false, | ||||
| 					"notNull": true | ||||
| 				} | ||||
| 			}, | ||||
| 			"indexes": {}, | ||||
| 			"foreignKeys": {}, | ||||
| 			"compositePrimaryKeys": {}, | ||||
| 			"uniqueConstraints": {} | ||||
| 		}, | ||||
| 		"public.visits": { | ||||
| 			"name": "visits", | ||||
| 			"schema": "", | ||||
| 			"columns": { | ||||
| 				"id": { | ||||
| 					"name": "id", | ||||
| 					"type": "serial", | ||||
| 					"primaryKey": true, | ||||
| 					"notNull": true | ||||
| 				}, | ||||
| 				"timestamp": { | ||||
| 					"name": "timestamp", | ||||
| 					"type": "timestamp with time zone", | ||||
| 					"primaryKey": false, | ||||
| 					"notNull": true, | ||||
| 					"default": "now()" | ||||
| 				}, | ||||
| 				"url_short_base64": { | ||||
| 					"name": "url_short_base64", | ||||
| 					"type": "text", | ||||
| 					"primaryKey": false, | ||||
| 					"notNull": true | ||||
| 				} | ||||
| 			}, | ||||
| 			"indexes": { | ||||
| 				"visits_url_short_base64_index": { | ||||
| 					"name": "visits_url_short_base64_index", | ||||
| 					"columns": [ | ||||
| 						{ | ||||
| 							"expression": "url_short_base64", | ||||
| 							"isExpression": false, | ||||
| 							"asc": true, | ||||
| 							"nulls": "last" | ||||
| 						} | ||||
| 					], | ||||
| 					"isUnique": false, | ||||
| 					"concurrently": false, | ||||
| 					"method": "hash", | ||||
| 					"with": {} | ||||
| 				}, | ||||
| 				"visits_timestamp_index": { | ||||
| 					"name": "visits_timestamp_index", | ||||
| 					"columns": [ | ||||
| 						{ | ||||
| 							"expression": "timestamp", | ||||
| 							"isExpression": false, | ||||
| 							"asc": true, | ||||
| 							"nulls": "last" | ||||
| 						} | ||||
| 					], | ||||
| 					"isUnique": false, | ||||
| 					"concurrently": false, | ||||
| 					"method": "btree", | ||||
| 					"with": {} | ||||
| 				} | ||||
| 			}, | ||||
| 			"foreignKeys": { | ||||
| 				"visits_url_short_base64_urls_short_base64_fk": { | ||||
| 					"name": "visits_url_short_base64_urls_short_base64_fk", | ||||
| 					"tableFrom": "visits", | ||||
| 					"tableTo": "urls", | ||||
| 					"columnsFrom": ["url_short_base64"], | ||||
| 					"columnsTo": ["short_base64"], | ||||
| 					"onDelete": "cascade", | ||||
| 					"onUpdate": "cascade" | ||||
| 				} | ||||
| 			}, | ||||
| 			"compositePrimaryKeys": {}, | ||||
| 			"uniqueConstraints": {} | ||||
| 		} | ||||
| 	}, | ||||
| 	"enums": {}, | ||||
| 	"schemas": {}, | ||||
| 	"_meta": { | ||||
| 		"columns": {}, | ||||
| 		"schemas": {}, | ||||
| 		"tables": {} | ||||
| 	} | ||||
| } | ||||
| @@ -2,7 +2,26 @@ | ||||
| 	"version": "5", | ||||
| 	"dialect": "pg", | ||||
| 	"entries": [ | ||||
| 		{ "idx": 0, "version": "5", "when": 1711606474248, "tag": "0000_sweet_marvel_apes", "breakpoints": true }, | ||||
| 		{ "idx": 1, "version": "7", "when": 1717471829465, "tag": "0001_minor_dormammu", "breakpoints": true } | ||||
| 		{ | ||||
| 			"idx": 0, | ||||
| 			"version": "5", | ||||
| 			"when": 1711606474248, | ||||
| 			"tag": "0000_sweet_marvel_apes", | ||||
| 			"breakpoints": true | ||||
| 		}, | ||||
| 		{ | ||||
| 			"idx": 1, | ||||
| 			"version": "7", | ||||
| 			"when": 1717471829465, | ||||
| 			"tag": "0001_minor_dormammu", | ||||
| 			"breakpoints": true | ||||
| 		}, | ||||
| 		{ | ||||
| 			"idx": 2, | ||||
| 			"version": "7", | ||||
| 			"when": 1717476347102, | ||||
| 			"tag": "0002_complex_pretty_boy", | ||||
| 			"breakpoints": true | ||||
| 		} | ||||
| 	] | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user