MCPcopy Index your code
hub / github.com/codebymitch/TitanBot / createTriggers

Function createTriggers

scripts/migrate.js:224–293  ·  view source on GitHub ↗
(client)

Source from the content-addressed store, hash-verified

222};
223
224const createTriggers = async (client) => {
225 logger.info('⏰ Setting up automatic timestamps...');
226
227 const triggers = [
228 {
229 table: 'guild_configs',
230 name: 'update_guild_configs_timestamp'
231 },
232 {
233 table: 'user_levels',
234 name: 'update_user_levels_timestamp'
235 },
236 {
237 table: 'user_economy',
238 name: 'update_user_economy_timestamp'
239 },
240 {
241 table: 'birthdays',
242 name: 'update_birthdays_timestamp'
243 },
244 {
245 table: 'tickets',
246 name: 'update_tickets_timestamp'
247 },
248 {
249 table: 'giveaways',
250 name: 'update_giveaways_timestamp'
251 },
252 {
253 table: 'reaction_roles',
254 name: 'update_reaction_roles_timestamp'
255 },
256 {
257 table: 'welcome_system',
258 name: 'update_welcome_system_timestamp'
259 },
260 {
261 table: 'counters',
262 name: 'update_counters_timestamp'
263 }
264 ];
265
266 for (const { table, name } of triggers) {
267 try {
268
269 await client.query(`
270 CREATE OR REPLACE FUNCTION update_timestamp_${table}()
271 RETURNS TRIGGER AS $$
272 BEGIN
273 NEW.updated_at = CURRENT_TIMESTAMP;
274 RETURN NEW;
275 END;
276 $$ LANGUAGE plpgsql;
277 `);
278
279 await client.query(`
280 DROP TRIGGER IF EXISTS ${name} ON ${table};
281 CREATE TRIGGER ${name}

Callers 1

migrateFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected