generated from well-known-components/template-server
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add missing indexes and constraints + prettier + redis host en …
…var usage
- Loading branch information
1 parent
d1b2885
commit 4593456
Showing
3 changed files
with
49 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* eslint-disable @typescript-eslint/naming-convention */ | ||
import { MigrationBuilder, ColumnDefinitions } from 'node-pg-migrate' | ||
|
||
export const shorthands: ColumnDefinitions | undefined = undefined | ||
|
||
export async function up(pgm: MigrationBuilder): Promise<void> { | ||
// Address indexes + constraints | ||
pgm.createIndex('friendships', 'address_requester', { name: 'friendships_address_requester', method: 'hash' }) | ||
pgm.createIndex('friendships', 'address_requested', { name: 'friendships_address_requested', method: 'hash' }) | ||
|
||
pgm.createConstraint('friendships', 'unique_addresses', { | ||
unique: ['address_requester', 'address_requested'] | ||
}) | ||
|
||
pgm.createConstraint('friendships', 'address_requester_smaller_than_address_requested', { | ||
check: 'address_requester < address_requested' | ||
}) | ||
|
||
// Lowercase indexes | ||
pgm.createIndex('friendships', 'LOWER(address_requester) text_pattern_ops', { | ||
name: 'friendships_address_requester_lower', | ||
method: 'btree' | ||
}) | ||
pgm.createIndex('friendships', 'LOWER(address_requested) text_pattern_ops', { | ||
name: 'friendships_address_requested_lower', | ||
method: 'btree' | ||
}) | ||
|
||
// Friendship history index | ||
pgm.createIndex('friendship_actions', 'friendship_id', { name: 'friendship_actions_friendship_id' }) | ||
} | ||
|
||
export async function down(pgm: MigrationBuilder): Promise<void> { | ||
pgm.dropIndex('friendships', 'friendships_address_requester') | ||
pgm.dropIndex('friendships', 'friendships_address_requested') | ||
pgm.dropConstraint('friendships', 'unique_addresses') | ||
pgm.dropConstraint('friendships', 'address_requester_smaller_than_address_requested') | ||
pgm.dropIndex('friendships', 'friendships_address_requester_lower') | ||
pgm.dropIndex('friendships', 'friendships_address_requested_lower') | ||
pgm.dropIndex('friendship_actions', 'friendship_actions_friendship_id') | ||
} |