Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testing for these migrations #9909

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libs/model/src/models/community.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export default (
},
base: { type: Sequelize.STRING, allowNull: false, defaultValue: '' },
ss58_prefix: { type: Sequelize.INTEGER, allowNull: true },
icon_url: { type: Sequelize.STRING },
icon_url: { type: Sequelize.STRING, allowNull: false },
active: { type: Sequelize.BOOLEAN, defaultValue: false },
stages_enabled: {
type: Sequelize.BOOLEAN,
Expand Down
2 changes: 1 addition & 1 deletion libs/schemas/src/entities/community.schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const Community = z.object({
default_symbol: z.string().default(''),
network: z.string().default(ChainNetwork.Ethereum),
base: z.nativeEnum(ChainBase),
icon_url: z.string().nullish(),
icon_url: z.string().optional(),
active: z.boolean(),
type: z.nativeEnum(ChainType).default(ChainType.Chain),
description: z.string().nullish(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
'use strict';

/** @type {import('sequelize-cli').Migration} */

module.exports = {
async up(queryInterface, Sequelize) {
await queryInterface.sequelize.transaction(async (transaction) => {
await queryInterface.sequelize.query(
`
WITH random_avatars AS (
SELECT id, (ARRAY[
'https://assets.commonwealth.im/6588c98e-8c2f-4ba1-a312-0ebda16861b7.png',
'https://assets.commonwealth.im/66422349-c5b2-4323-9f55-4750eaac5162.png',
'https://assets.commonwealth.im/ea18afa6-158f-4fa2-b28b-1f51d88a1ad1.png',
'https://assets.commonwealth.im/beaf8336-eb27-43e8-9d81-feaefcdb8db9.png',
'https://assets.commonwealth.im/5a2f2012-22a5-469e-9214-a0a2d84ecbef.png',
'https://assets.commonwealth.im/128e3b82-fd5d-4f1d-bdcc-5e23336f299f.png',
])[floor(random() * 6 + 1)] AS avatar_url
FROM "Communities"
WHERE 'icon_url' IS NULL
OR 'icon_url' = ''
)
UPDATE "Communities"
SET icon_url = random_avatars.avatar_url
FROM random_avatars
WHERE "Communities".id = random_avatars.id
`,
{ transaction },
);

await queryInterface.sequelize.query(
`
ALTER TABLE "Communities"
ALTER COLUMN "icon_url" SET NOT NULL;
`,
{ transaction },
);
});
},

async down(queryInterface, Sequelize) {},
};
Loading