Skip to content
This repository has been archived by the owner on May 19, 2023. It is now read-only.

Commit

Permalink
feat: add migration for lower-casing addresses in storage (#448)
Browse files Browse the repository at this point in the history
  • Loading branch information
nduchak authored Dec 10, 2020
1 parent 90c842d commit a4b9591
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion config/ganache.json5
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
storage: {
enabled: true,
tokens: {
'0x67B5656d60a809915323Bf2C40A8bEF15A152e3e': 'rif'
'0x67b5656d60a809915323bf2c40a8bef15a152e3e': 'rif'
},
storageManager: {
contractAddress: "0xDDb64fE46a91D46ee29420539FC25FD07c5FEa3E",
Expand Down
4 changes: 2 additions & 2 deletions src/cli/db-migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
22 changes: 22 additions & 0 deletions src/migrations/scripts/1607591688470-lower-case-address-columns.ts
Original file line number Diff line number Diff line change
@@ -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<void> {
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<void> {}
}

0 comments on commit a4b9591

Please sign in to comment.