1
- import type { SupabaseClient , SupabaseProviderMetadata } from './types.js'
2
1
import { exec as execSync } from 'node:child_process'
3
2
import { promisify } from 'node:util'
4
- import { createDeployedDatabase } from './create-deployed-database.js'
5
- import { getDatabaseUrl , getPoolerUrl } from './get-database-url.js'
6
- import { DeployError , IntegrationRevokedError } from '../error.js'
7
- import { generatePassword } from './generate-password.js'
8
- import { getAccessToken } from './get-access-token.js'
9
- import { createManagementApiClient } from './management-api/client.js'
3
+ import { DeployError , IntegrationRevokedError } from '@database.build/deploy'
4
+ import {
5
+ getAccessToken ,
6
+ createManagementApiClient ,
7
+ createDeployedDatabase ,
8
+ generatePassword ,
9
+ getDatabaseUrl ,
10
+ getPoolerUrl ,
11
+ type SupabaseClient ,
12
+ type SupabaseDeploymentConfig ,
13
+ type SupabasePlatformConfig ,
14
+ type SupabaseProviderMetadata ,
15
+ } from '@database.build/deploy/supabase'
10
16
const exec = promisify ( execSync )
11
17
12
18
/**
13
19
* Deploy a local database on Supabase
14
20
* If the database was already deployed, it will overwrite the existing database data
15
21
*/
16
22
export async function deploy (
17
- ctx : { supabase : SupabaseClient } ,
23
+ ctx : {
24
+ supabase : SupabaseClient
25
+ supabaseAdmin : SupabaseClient
26
+ supabasePlatformConfig : SupabasePlatformConfig
27
+ supabaseDeploymentConfig : SupabaseDeploymentConfig
28
+ } ,
18
29
params : { databaseId : string ; integrationId : number ; localDatabaseUrl : string }
19
30
) {
20
31
// check if the integration is still active
@@ -32,13 +43,13 @@ export async function deploy(
32
43
throw new IntegrationRevokedError ( )
33
44
}
34
45
35
- const accessToken = await getAccessToken ( {
46
+ const accessToken = await getAccessToken ( ctx , {
36
47
integrationId : params . integrationId ,
37
48
// the integration isn't revoked, so it must have credentials
38
49
credentialsSecretId : integration . data . credentials ! ,
39
50
} )
40
51
41
- const managementApiClient = createManagementApiClient ( accessToken )
52
+ const managementApiClient = createManagementApiClient ( ctx , accessToken )
42
53
43
54
// this is just to check if the integration is still active, an IntegrationRevokedError will be thrown if not
44
55
await managementApiClient . GET ( '/v1/organizations' )
@@ -75,10 +86,10 @@ export async function deploy(
75
86
let databasePassword : string | undefined
76
87
77
88
if ( ! deployedDatabase . data ) {
78
- const createdDeployedDatabase = await createDeployedDatabase (
79
- { supabase : ctx . supabase } ,
80
- { databaseId : params . databaseId , integrationId : params . integrationId }
81
- )
89
+ const createdDeployedDatabase = await createDeployedDatabase ( ctx , {
90
+ databaseId : params . databaseId ,
91
+ integrationId : params . integrationId ,
92
+ } )
82
93
83
94
deployedDatabase . data = createdDeployedDatabase . deployedDatabase
84
95
databasePassword = createdDeployedDatabase . databasePassword
@@ -186,7 +197,7 @@ export async function deploy(
186
197
187
198
return {
188
199
name : project . name ,
189
- url : `${ process . env . SUPABASE_PLATFORM_URL } /dashboard/project/${ project . id } ` ,
200
+ url : `${ ctx . supabasePlatformConfig . url } /dashboard/project/${ project . id } ` ,
190
201
databasePassword,
191
202
databaseUrl : getDatabaseUrl ( { project, databasePassword } ) ,
192
203
poolerUrl : getPoolerUrl ( { project, databasePassword } ) ,
0 commit comments