51 lines
1.3 KiB
JavaScript
51 lines
1.3 KiB
JavaScript
/**
|
||
* @type {import('node-pg-migrate').ColumnDefinitions | undefined}
|
||
*/
|
||
export const shorthands = undefined;
|
||
|
||
/**
|
||
* @param pgm {import('node-pg-migrate').MigrationBuilder}
|
||
* @param run {() => void | undefined}
|
||
* @returns {Promise<void> | void}
|
||
*/
|
||
export const up = (pgm) => {
|
||
// Создание представления для совместимости со старым кодом (swipes)
|
||
pgm.sql(`
|
||
CREATE OR REPLACE VIEW swipes_view AS
|
||
SELECT
|
||
id,
|
||
user_id AS swiper_id,
|
||
target_user_id AS swiped_id,
|
||
type AS direction,
|
||
created_at,
|
||
is_match
|
||
FROM swipes;
|
||
`);
|
||
|
||
// Создание представления для совместимости со старым кодом (matches)
|
||
pgm.sql(`
|
||
CREATE OR REPLACE VIEW matches_view AS
|
||
SELECT
|
||
id,
|
||
user_id_1 AS user1_id,
|
||
user_id_2 AS user2_id,
|
||
created_at AS matched_at,
|
||
is_active AS status,
|
||
last_message_at,
|
||
is_super_match,
|
||
unread_count_1,
|
||
unread_count_2
|
||
FROM matches;
|
||
`);
|
||
};
|
||
|
||
/**
|
||
* @param pgm {import('node-pg-migrate').MigrationBuilder}
|
||
* @param run {() => void | undefined}
|
||
* @returns {Promise<void> | void}
|
||
*/
|
||
export const down = (pgm) => {
|
||
pgm.sql(`DROP VIEW IF EXISTS swipes_view;`);
|
||
pgm.sql(`DROP VIEW IF EXISTS matches_view;`);
|
||
};
|