-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add fromFS option to /ipfs path * Add migration to support direct dir cid queries and make rehydration async * Add comment * Fix lint * Remove commented out code * Fix comma * Remove \n\n\n * Clean up * Fix index * Rebase & install * Lint * Clean up and paginate query * Fix migration * Comment out update * Reset route changes * Lint fix
- Loading branch information
1 parent
fbab25f
commit 6f9c0e9
Showing
3 changed files
with
99 additions
and
3 deletions.
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
creator-node/sequelize/migrations/20200623002237-add-parent-file-data.js
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,73 @@ | ||
'use strict' | ||
|
||
/** | ||
* Adds two columns to the `files` table | ||
* - fileName: the actual queryable source filename stripped of any prefixes | ||
* - dirMultihash: if the file is in an IPFS directory, the CID/multihash for the parent dir | ||
*/ | ||
module.exports = { | ||
up: async (queryInterface, Sequelize) => { | ||
const transaction = await queryInterface.sequelize.transaction() | ||
try { | ||
await queryInterface.addColumn( | ||
'Files', | ||
'fileName', | ||
{ | ||
type: Sequelize.TEXT, | ||
allowNull: true | ||
}, | ||
{ transaction } | ||
) | ||
await queryInterface.addColumn( | ||
'Files', | ||
'dirMultihash', | ||
{ | ||
type: Sequelize.TEXT, | ||
allowNull: true | ||
}, | ||
{ transaction } | ||
) | ||
await queryInterface.addIndex('Files', ['dirMultihash'], { transaction }) | ||
|
||
// For reference, this is what the values of the columns should be | ||
// inherited from sourceFile & storagePath | ||
// This bulk update is run separaely. | ||
|
||
// await queryInterface.sequelize.query(` | ||
// UPDATE "Files" SET | ||
// "fileName" = regexp_replace("sourceFile", '(.*)\/','','g'), | ||
// "dirMultihash" = CASE | ||
// WHEN "type" = 'image' THEN regexp_replace("storagePath", '^\/.*/(Qm.*)\/(Qm.*)$','\\1','g') | ||
// ELSE null | ||
// END | ||
// `, { transaction }) | ||
|
||
await transaction.commit() | ||
} catch (err) { | ||
await transaction.rollback() | ||
throw err | ||
} | ||
}, | ||
|
||
down: async (queryInterface, Sequelize) => { | ||
const transaction = await queryInterface.sequelize.transaction() | ||
try { | ||
await queryInterface.removeColumn( | ||
'Files', | ||
'fileName', | ||
{ transaction } | ||
) | ||
await queryInterface.removeColumn( | ||
'Files', | ||
'dirMultihash', | ||
{ transaction } | ||
) | ||
|
||
await queryInterface.removeIndex('Files', ['dirMultihash'], { transaction }) | ||
await transaction.commit() | ||
} catch (err) { | ||
await transaction.rollback() | ||
throw err | ||
} | ||
} | ||
} |
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