Skip to content

Commit

Permalink
[FEATURE]: add javascript usage for scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
Behzad-rabiei committed Sep 20, 2023
1 parent aed7fa9 commit 967d7a5
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 23 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ src/config/*.env
*.env

# compiled output
/lib
/dist
/node_modules

#migration
migrate.json
.migrate
# Logs
logs
*.log
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
"lint": "eslint **/*.ts",
"lint-fix": "eslint --fix **/*.ts",
"format": "prettier --write src/**/*.ts",
"migrate:create": "migrate create --template-file ./src/migrations/utils/template.ts --migrations-dir=\"./src/migrations/db\" --compiler=\"ts:./src/migrations/utils/ts-compiler.js\"",
"migrate:up": "migrate --migrations-dir=\"./src/migrations/db\" --compiler=\"ts:./src/migrations/utils/ts-compiler.js\" up",
"migrate:down": "migrate --migrations-dir=\"./src/migrations/db\" --compiler=\"ts:./src/migrations/utils/ts-compiler.js\" down"
"migrate:create": "migrate create --template-file ./src/migrations/utils/template.ts --migrations-dir=\"./src/migrations/db\"",
"migrate:up": "migrate --migrations-dir=\"./dist/migrations/db\" up",
"migrate:down": "migrate --migrations-dir=\"./dist/migrations/db\" down"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -67,4 +67,4 @@
"ts-node": "^10.9.1",
"typescript": "^5.0.4"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@ export const up = async () => {

export const down = async () => {
// TODO: Implement rollback logic if needed
};
};


14 changes: 0 additions & 14 deletions src/migrations/utils/webhookLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ async function fetchMessagesBetweenOldestAndNewest(
) {
try {
let allMessages: Message[] = [];
logger.info(
{ guild_id: connection.name, channel_id: channel.id },
'Fetching channel messages is running'
);
const options: FetchOptions = { limit: 100 };
options.after = oldestRawInfo.messageId;
let fetchedMessages = await channel.messages.fetch(options);
Expand All @@ -42,16 +38,10 @@ async function fetchMessagesBetweenOldestAndNewest(
'Fetching channel messages failed'
);
}
logger.info(
{ guild_id: connection.name, channel_id: channel.id },
'Fetching channel messages is done'
);
}

async function migrateIsGeneratedByWebhook(connection: Connection, channel: TextChannel) {
try {
logger.info({ guild_id: connection.name, channel_id: channel.id }, 'Migration for isGeneratedByWebhook is running');

// Fetch oldest rawInfo from DB
const oldestChannelRawInfo = await rawInfoService.getOldestRawInfo(connection, {
channelId: channel?.id,
Expand Down Expand Up @@ -159,8 +149,6 @@ async function migrateIsGeneratedByWebhook(connection: Connection, channel: Text
}
}

logger.info({ guild_id: connection.name, channel_id: channel.id }, 'Migration for isGeneratedByWebhook is done');

} catch (err) {
logger.error({ guild_id: connection.name, channel_id: channel.id, err }, 'Migration for isGeneratedByWebhook failed');
}
Expand All @@ -174,7 +162,6 @@ async function migrateIsGeneratedByWebhook(connection: Connection, channel: Text
* @param {Snowflake} guildId - The identifier of the guild to extract information from.
*/
async function runRawInfoMigration(connection: Connection, client: Client, guildId: Snowflake) {
logger.info({ guild_id: guildId }, 'Migration is running');
try {
const guild = await client.guilds.fetch(guildId);
const channels = await channelService.getChannels(connection, {});
Expand All @@ -188,7 +175,6 @@ async function runRawInfoMigration(connection: Connection, client: Client, guild
} catch (err) {
logger.error({ guild_id: guildId, err }, 'Migration is failed');
}
logger.info({ guild_id: guildId }, 'Migration is done');
}

export default runRawInfoMigration;
6 changes: 3 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "ES2017",
"sourceMap": true,
"outDir": "./lib",
"sourceMap": false,
"outDir": "./dist",
"baseUrl": "./",
"incremental": true,
"strict": true,
Expand All @@ -26,7 +26,7 @@
},
"exclude": [
"./coverage",
"./lib",
"./dist",
"__tests__",
"jest.config.js"
],
Expand Down

0 comments on commit 967d7a5

Please sign in to comment.