mainly functional matching
This commit is contained in:
44
migrations/1631980000000_add_profile_views_table.ts
Normal file
44
migrations/1631980000000_add_profile_views_table.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import { MigrationBuilder, ColumnDefinitions } from 'node-pg-migrate';
|
||||
|
||||
export const shorthands: ColumnDefinitions | undefined = undefined;
|
||||
|
||||
export async function up(pgm: MigrationBuilder): Promise<void> {
|
||||
// Создание таблицы profile_views для хранения информации о просмотренных профилях
|
||||
pgm.createTable('profile_views', {
|
||||
id: { type: 'uuid', primaryKey: true, default: pgm.func('uuid_generate_v4()') },
|
||||
viewer_id: {
|
||||
type: 'uuid',
|
||||
notNull: true,
|
||||
references: 'users',
|
||||
onDelete: 'CASCADE'
|
||||
},
|
||||
viewed_profile_id: {
|
||||
type: 'uuid',
|
||||
notNull: true,
|
||||
references: 'profiles(user_id)',
|
||||
onDelete: 'CASCADE'
|
||||
},
|
||||
view_date: { type: 'timestamp', notNull: true, default: pgm.func('now()') },
|
||||
view_type: { type: 'varchar(20)', notNull: true, default: 'browse' }, // browse, match, like, etc.
|
||||
});
|
||||
|
||||
// Создание индекса для быстрого поиска по паре (просмотревший - просмотренный)
|
||||
pgm.createIndex('profile_views', ['viewer_id', 'viewed_profile_id'], {
|
||||
unique: true,
|
||||
name: 'profile_views_viewer_viewed_idx'
|
||||
});
|
||||
|
||||
// Индекс для быстрого поиска по viewer_id
|
||||
pgm.createIndex('profile_views', ['viewer_id'], {
|
||||
name: 'profile_views_viewer_idx'
|
||||
});
|
||||
|
||||
// Индекс для быстрого поиска по viewed_profile_id
|
||||
pgm.createIndex('profile_views', ['viewed_profile_id'], {
|
||||
name: 'profile_views_viewed_idx'
|
||||
});
|
||||
}
|
||||
|
||||
export async function down(pgm: MigrationBuilder): Promise<void> {
|
||||
pgm.dropTable('profile_views', { cascade: true });
|
||||
}
|
||||
Reference in New Issue
Block a user