@@ -67,24 +67,30 @@ async function moveWorkspace (
67
67
mongo : MongoClient ,
68
68
pgClient : postgres . Sql ,
69
69
ws : Workspace ,
70
- region : string
70
+ region : string ,
71
+ include ?: Set < string >
71
72
) : Promise < void > {
72
73
try {
73
74
const wsId = getWorkspaceId ( ws . workspace )
74
75
const mongoDB = getWorkspaceMongoDB ( mongo , wsId )
75
76
const collections = await mongoDB . collections ( )
76
- await createTable (
77
- pgClient ,
78
- collections . map ( ( c ) => c . collectionName )
79
- )
77
+ let tables = collections . map ( ( c ) => c . collectionName )
78
+ if ( include !== undefined ) {
79
+ tables = tables . filter ( ( t ) => include . has ( t ) )
80
+ }
81
+
82
+ await createTable ( pgClient , tables )
80
83
const token = generateToken ( systemAccountEmail , wsId )
81
84
const endpoint = await getTransactorEndpoint ( token , 'external' )
82
85
const connection = ( await connect ( endpoint , wsId , undefined , {
83
86
model : 'upgrade'
84
87
} ) ) as unknown as Client & BackupClient
85
88
for ( const collection of collections ) {
86
- const cursor = collection . find ( )
87
89
const domain = translateDomain ( collection . collectionName )
90
+ if ( include !== undefined && ! include . has ( domain ) ) {
91
+ continue
92
+ }
93
+ const cursor = collection . find ( )
88
94
const current = await pgClient `SELECT _id FROM ${ pgClient ( domain ) } WHERE "workspaceId" = ${ ws . workspace } `
89
95
const currentIds = new Set ( current . map ( ( r ) => r . _id ) )
90
96
console . log ( 'move domain' , domain )
@@ -131,7 +137,8 @@ export async function moveWorkspaceFromMongoToPG (
131
137
mongoUrl : string ,
132
138
dbUrl : string | undefined ,
133
139
ws : Workspace ,
134
- region : string
140
+ region : string ,
141
+ include ?: Set < string >
135
142
) : Promise < void > {
136
143
if ( dbUrl === undefined ) {
137
144
throw new Error ( 'dbUrl is required' )
@@ -141,7 +148,7 @@ export async function moveWorkspaceFromMongoToPG (
141
148
const pg = getDBClient ( dbUrl )
142
149
const pgClient = await pg . getClient ( )
143
150
144
- await moveWorkspace ( accountDb , mongo , pgClient , ws , region )
151
+ await moveWorkspace ( accountDb , mongo , pgClient , ws , region , include )
145
152
pg . close ( )
146
153
client . close ( )
147
154
}
0 commit comments