Skip to content
This repository has been archived by the owner on Oct 31, 2024. It is now read-only.

Commit

Permalink
adding migrate tables option (#49)
Browse files Browse the repository at this point in the history
* adding migrate tables option

* fixing pg defs
  • Loading branch information
pellicceama authored Oct 17, 2024
1 parent 3e9d1b1 commit 598903d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
3 changes: 2 additions & 1 deletion connectors/connector-postgres/def.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const zPgConfig = z.object({
migrationsPath: z.string().optional(),
migrationTableName: z.string().optional(),
transformFieldNames: z.boolean().optional(),
migrateTables: z.boolean().optional(),
})

export const postgresSchemas = {
Expand All @@ -19,7 +20,7 @@ export const postgresSchemas = {
// if it's resourceSettings then it doesn't make as much sense to configure
// in the list of integrations...
// How do we create default resources for integrations that are basically single resource?
resourceSettings: zPgConfig.pick({databaseUrl: true}).extend({
resourceSettings: zPgConfig.pick({databaseUrl: true, migrateTables: true}).extend({
// gotta make sourceQueries a Textarea

sourceQueries: z
Expand Down
6 changes: 5 additions & 1 deletion connectors/connector-postgres/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ export const postgresServer = {
),
)
},
destinationSync: ({endUser, source, settings: {databaseUrl}}) => {
destinationSync: ({endUser, source, settings: {databaseUrl, migrateTables}}) => {
console.log('[destinationSync] Will makePostgresClient', {
// databaseUrl,
// migrationsPath: __dirname + '/migrations',
Expand All @@ -210,6 +210,10 @@ export const postgresServer = {

const migrationRan: Record<string, boolean> = {}
async function runMigration(pool: DatabasePool, tableName: string) {
if (!migrateTables) {
console.log('[destinationSync] Will not run migration for', tableName, 'as migrateTables is false');
return;
}
console.log('will run migration for', tableName)
if (migrationRan[tableName]) {
return
Expand Down
5 changes: 5 additions & 0 deletions packages/engine-backend/services/AuthProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ export const zOrganization = z.object({
description:
'Events like sync.completed and connection.created can be sent to url of your choosing',
}),
migrate_tables: z.boolean().optional().openapi({
title: 'Migrate Tables',
description: 'If enabled, table migrations will be run if needed when entities are persisted',
default: true,
}),
}),
privateMetadata: z
.object({
Expand Down
2 changes: 1 addition & 1 deletion packages/engine-backend/services/sync-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export function makeSyncService({
await metaLinks.patch('resource', defaultDestId, {
connectorConfigId: dCcfgId,
// Should always snake_case here. This is also not typesafe...
settings: {databaseUrl: org.publicMetadata.database_url},
settings: {databaseUrl: org.publicMetadata.database_url, migrateTables: org.publicMetadata.migrate_tables},
})
console.log('Created default resource', defaultDestId)
}
Expand Down

1 comment on commit 598903d

@vercel
Copy link

@vercel vercel bot commented on 598903d Oct 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.