|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +module.exports = { |
| 4 | + up: async (queryInterface, Sequelize) => { |
| 5 | + const transaction = await queryInterface.sequelize.transaction(); |
| 6 | + try { |
| 7 | + await queryInterface.sequelize.query('DROP VIEW view_tokens;', { transaction }); |
| 8 | + await queryInterface.sequelize.query(` |
| 9 | + --beginsql |
| 10 | + CREATE OR REPLACE VIEW public.view_tokens as |
| 11 | + select |
| 12 | + t.token_id, t.collection_id, t.data, t.owner, |
| 13 | + coalesce( |
| 14 | + t.data::json->>'ipfsJson', |
| 15 | + replace(coalesce(c.offchain_schema, ''), '{id}', t.token_id::varchar(255)), |
| 16 | + '' |
| 17 | + ) as image_path, |
| 18 | + c.token_prefix as token_prefix, |
| 19 | + c.name as collection_name, |
| 20 | + c.description as collection_description, |
| 21 | + c.variable_on_chain_schema::json ->> 'collectionCover'::text AS collection_cover, |
| 22 | + t.date_of_creation |
| 23 | + from tokens t |
| 24 | + left join collections c on c.collection_id = t.collection_id |
| 25 | + --endsql |
| 26 | + `, { |
| 27 | + transaction |
| 28 | + }); |
| 29 | + await transaction.commit(); |
| 30 | + } catch (err) { |
| 31 | + console.error(err); |
| 32 | + await transaction.rollback(); |
| 33 | + throw err; |
| 34 | + } |
| 35 | + }, |
| 36 | + |
| 37 | + down: async (queryInterface, Sequelize) => { |
| 38 | + const transaction = await queryInterface.sequelize.transaction(); |
| 39 | + try { |
| 40 | + await queryInterface.sequelize.query('DROP VIEW view_tokens;', { transaction }); |
| 41 | + await queryInterface.sequelize.query(` |
| 42 | + --beginsql |
| 43 | + CREATE OR REPLACE VIEW public.view_tokens as |
| 44 | + select |
| 45 | + t.token_id, t.collection_id, t.data, t.owner, |
| 46 | + coalesce( |
| 47 | + t.data::json->>'ipfsJson', |
| 48 | + replace(coalesce(c.offchain_schema, ''), '{id}', t.token_id::varchar(255)), |
| 49 | + '' |
| 50 | + ) as image_path, |
| 51 | + c.token_prefix as token_prefix, |
| 52 | + c.name as collection_name, |
| 53 | + c.description as collection_description, |
| 54 | + c.variable_on_chain_schema::json ->> 'collectionCover'::text AS collection_cover |
| 55 | + from tokens t |
| 56 | + left join collections c on c.collection_id = t.collection_id |
| 57 | + --endsql |
| 58 | + `, { |
| 59 | + transaction |
| 60 | + }); |
| 61 | + await transaction.commit(); |
| 62 | + } catch (err) { |
| 63 | + console.error(err); |
| 64 | + await transaction.rollback(); |
| 65 | + throw err; |
| 66 | + } |
| 67 | + } |
| 68 | +}; |
0 commit comments