diff --git a/config/ganache.json5 b/config/ganache.json5 index ee9a798d..d3bdfff9 100644 --- a/config/ganache.json5 +++ b/config/ganache.json5 @@ -7,7 +7,7 @@ storage: { enabled: true, tokens: { - '0x67B5656d60a809915323Bf2C40A8bEF15A152e3e': 'rif' + '0x67b5656d60a809915323bf2c40a8bef15a152e3e': 'rif' }, storageManager: { contractAddress: "0xDDb64fE46a91D46ee29420539FC25FD07c5FEa3E", diff --git a/src/cli/db-migration.ts b/src/cli/db-migration.ts index 0c9e197b..ff9cb2e7 100644 --- a/src/cli/db-migration.ts +++ b/src/cli/db-migration.ts @@ -114,8 +114,8 @@ export default class DbMigrationCommand extends BaseCLICommand { } generateMigration (name: string): void { - const migrationsFolder = path.resolve(process.cwd(), './migrations') - const scriptsFolder = path.resolve(process.cwd(), './migrations/scripts') + const migrationsFolder = path.resolve(__dirname, '../migrations') + const scriptsFolder = path.resolve(__dirname, '../migrations/scripts') const fileName = `./${Date.now()}-${name}.ts` const filePath = path.resolve(scriptsFolder, fileName) diff --git a/src/migrations/scripts/1607591688470-lower-case-address-columns.ts b/src/migrations/scripts/1607591688470-lower-case-address-columns.ts new file mode 100644 index 00000000..9011c019 --- /dev/null +++ b/src/migrations/scripts/1607591688470-lower-case-address-columns.ts @@ -0,0 +1,22 @@ +import { QueryInterface } from 'sequelize' +import { Sequelize } from 'sequelize-typescript' + +export default { + // eslint-disable-next-line require-await + async up (queryInterface: QueryInterface, sequelize: Sequelize): Promise { + const transaction = await sequelize.transaction() + try { + await sequelize.query('UPDATE storage_offer SET provider = lower(provider)', { transaction }) + await sequelize.query('UPDATE "storage_billing-plan" SET tokenAddress = lower(tokenAddress), offerId = lower(offerId)', { transaction }) + await sequelize.query('UPDATE storage_agreement SET consumer = lower(consumer), tokenAddress = lower(tokenAddress), offerId = lower(offerId)', { transaction }) + await sequelize.query('UPDATE storage_stakes SET account = lower(account), token = lower(token)', { transaction }) + + await transaction.commit() + } catch (e) { + await transaction.rollback() + } + }, + // Lower-casing can not be restored + // eslint-disable-next-line require-await,@typescript-eslint/no-empty-function + async down (queryInterface: QueryInterface, sequelize: Sequelize): Promise {} +}