-
Notifications
You must be signed in to change notification settings - Fork 368
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
Refactor track_deletes #1892
Refactor track_deletes #1892
Changes from all commits
68acdc7
cc9cd24
605b503
574bb59
9bbe8e8
3ac0ec6
39c888e
8a3d5b8
12238c5
0e7282d
8d0cbd3
57ced19
f2e2ae7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
const RECORDS_TABLE = '_nango_sync_data_records'; | ||
exports.up = async function (knex) { | ||
await knex.transaction((trx) => { | ||
return trx | ||
.raw( | ||
` | ||
CREATE OR REPLACE FUNCTION ${RECORDS_TABLE}_reset_created_at() | ||
RETURNS TRIGGER AS $$ | ||
BEGIN | ||
IF OLD.external_deleted_at IS NOT NULL AND NEW.external_deleted_at IS NULL THEN | ||
NEW.created_at = NOW(); | ||
NEW.updated_at = NOW(); | ||
NEW.external_is_deleted = FALSE; | ||
END IF; | ||
RETURN NEW; | ||
END; | ||
$$ LANGUAGE plpgsql; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no way to have this logic in the code? I'm really not fond of sql logic, it's hard to debug and easy to forget There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am also not a huge fan of the fact it is easy to forget. The alternative would be to fetch all existing records and compare before merging |
||
` | ||
) | ||
.then(function () { | ||
return trx.raw(` | ||
CREATE TRIGGER ${RECORDS_TABLE}_reset_created_at_trigger | ||
BEFORE UPDATE ON ${RECORDS_TABLE} | ||
FOR EACH ROW | ||
EXECUTE FUNCTION ${RECORDS_TABLE}_reset_created_at(); | ||
`); | ||
}); | ||
}); | ||
}; | ||
|
||
exports.down = async function (knex) { | ||
await knex.transaction((trx) => { | ||
return trx.raw(`DROP TRIGGER IF EXISTS ${RECORDS_TABLE}_reset_created_at_trigger ON ${RECORDS_TABLE};`).then(function () { | ||
return trx.raw(`DROP FUNCTION IF EXISTS ${RECORDS_TABLE}_reset_created_at();`); | ||
}); | ||
}); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,26 @@ | ||
import { schema } from '../database.js'; | ||
import configService from '../../services/config.service.js'; | ||
import environmentService from '../../services/environment.service.js'; | ||
import type { Config as ProviderConfig } from '../../models/Provider.js'; | ||
import type { Environment } from '../../models/Environment.js'; | ||
|
||
export const createConfigSeeds = async (environmentName = ''): Promise<Environment[]> => { | ||
let result: Environment[]; | ||
if (environmentName) { | ||
result = [(await environmentService.createEnvironment(0, environmentName))!]; | ||
} else { | ||
result = await schema().select('*').from('_nango_environments'); | ||
} | ||
|
||
for (const row of result) { | ||
const { id: environment_id } = row; | ||
await configService.createProviderConfig({ | ||
unique_key: Math.random().toString(36).substring(7), | ||
provider: 'google', | ||
environment_id | ||
} as ProviderConfig); | ||
await configService.createProviderConfig({ | ||
unique_key: Math.random().toString(36).substring(7), | ||
provider: 'google', | ||
environment_id | ||
} as ProviderConfig); | ||
await configService.createProviderConfig({ | ||
unique_key: Math.random().toString(36).substring(7), | ||
provider: 'google', | ||
environment_id | ||
} as ProviderConfig); | ||
await configService.createProviderConfig({ | ||
unique_key: Math.random().toString(36).substring(7), | ||
provider: 'notion', | ||
environment_id | ||
} as ProviderConfig); | ||
} | ||
|
||
return result; | ||
export const createConfigSeeds = async (env: Environment): Promise<void> => { | ||
await configService.createProviderConfig({ | ||
unique_key: Math.random().toString(36).substring(7), | ||
provider: 'google', | ||
environment_id: env.id | ||
} as ProviderConfig); | ||
await configService.createProviderConfig({ | ||
unique_key: Math.random().toString(36).substring(7), | ||
provider: 'google', | ||
environment_id: env.id | ||
} as ProviderConfig); | ||
await configService.createProviderConfig({ | ||
unique_key: Math.random().toString(36).substring(7), | ||
provider: 'google', | ||
environment_id: env.id | ||
} as ProviderConfig); | ||
await configService.createProviderConfig({ | ||
unique_key: Math.random().toString(36).substring(7), | ||
provider: 'notion', | ||
environment_id: env.id | ||
} as ProviderConfig); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import type { Environment } from '../../models/Environment.js'; | ||
import environmentService from '../../services/environment.service.js'; | ||
|
||
export async function createEnvironmentSeed(envName: string = 'test'): Promise<Environment> { | ||
const env = await environmentService.createEnvironment(0, envName); | ||
if (!env) { | ||
throw new Error('Failed to create environment'); | ||
} | ||
return env; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unrelated to track_deletes: making environment id not optional, same from sync and syncJob below