Skip to content

Commit

Permalink
feat(cli): support database export and import (#1540)
Browse files Browse the repository at this point in the history
* feat: support cli export db

* feat: support database import and export
  • Loading branch information
skyoct authored Sep 19, 2023
1 parent 86250d9 commit 8c68089
Show file tree
Hide file tree
Showing 19 changed files with 1,589 additions and 123 deletions.
34 changes: 34 additions & 0 deletions cli/src/action/database/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { databaseControllerExport, databaseControllerImport } from "../../api/custom";
import { AppSchema } from "../../schema/app";
import * as fs from 'fs'
import { getEmoji } from "../../util/print";
import * as path from 'path'
import { exist } from "../../util/file";
import * as FormData from 'form-data'

export async function exportDB(exportPath: string): Promise<void> {
const appSchema = AppSchema.read()

const res = await databaseControllerExport(appSchema.appid)
// get absolute path
const absPath = path.resolve(exportPath)
res.pipe(fs.createWriteStream(path.join(absPath, `${appSchema.appid}-db.gz`)))
console.log(`${getEmoji('✅')} database export success`)
}

export async function importDB(sourceAppid, importPath: string): Promise<void> {
const appSchema = AppSchema.read()

// get absolute path
const absPath = path.resolve(importPath)
if (!exist(absPath)) {
console.log(`${getEmoji('❌')} import database file not exist`)
return
}

const formData = new FormData();
formData.append('file', fs.createReadStream(absPath), 'database.gz')
formData.append('sourceAppid', sourceAppid)
await databaseControllerImport(appSchema.appid, formData)
console.log(`${getEmoji('✅')} database import success`)
}
1 change: 1 addition & 0 deletions cli/src/action/function/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ async function push(funcName: string, isCreate: boolean) {
await functionControllerCreate(appSchema.appid, createDto)
} else {
const updateDto: UpdateFunctionDto = {
newName: funcName,
description: funcSchema.description || '',
methods: funcSchema.methods as any,
code,
Expand Down
21 changes: 21 additions & 0 deletions cli/src/api/custom.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { request } from "../util/request";


export async function databaseControllerExport(appid: string):Promise<any> {
return request({
url: `/v1/apps/${appid}/databases/export`,
method: 'GET',
responseType: 'stream',
})
}

export async function databaseControllerImport(appid: string, data: any):Promise<any> {
return request({
url: `/v1/apps/${appid}/databases/import`,
method: 'PUT',
data: data,
headers: {
'Content-Type': 'multipart/form-data'
}
})
}
118 changes: 117 additions & 1 deletion cli/src/api/v1/account.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import { request, RequestParams } from "../../util/request";
import { AccountControllerWechatNotifyData, CreateChargeOrderDto } from "./data-contracts";
import {
AccountControllerGetChargeOrderAmountParams,
AccountControllerGetChargeRecordsParams,
AccountControllerInviteCodeProfitParams,
AccountControllerWechatNotifyData,
CreateChargeOrderDto,
UseGiftCodeDto,
} from "./data-contracts";

/**
* No description
Expand All @@ -17,6 +24,26 @@ export async function accountControllerFindOne(configParams: RequestParams = {})
...configParams,
});
}
/**
* No description
*
* @tags Account
* @name AccountControllerGetChargeOrderAmount
* @summary Get charge order total amount
* @request GET:/v1/accounts/charge-order/amount
* @secure
*/
export async function accountControllerGetChargeOrderAmount(
query: AccountControllerGetChargeOrderAmountParams,
configParams: RequestParams = {},
): Promise<any> {
return request({
url: `/v1/accounts/charge-order/amount`,
method: "GET",
params: query,
...configParams,
});
}
/**
* No description
*
Expand All @@ -33,6 +60,26 @@ export async function accountControllerGetChargeOrder(id: string, configParams:
...configParams,
});
}
/**
* No description
*
* @tags Account
* @name AccountControllerGetChargeRecords
* @summary get all charge order
* @request GET:/v1/accounts/charge-orders
* @secure
*/
export async function accountControllerGetChargeRecords(
query: AccountControllerGetChargeRecordsParams,
configParams: RequestParams = {},
): Promise<any> {
return request({
url: `/v1/accounts/charge-orders`,
method: "GET",
params: query,
...configParams,
});
}
/**
* No description
*
Expand All @@ -53,6 +100,22 @@ export async function accountControllerCharge(
...configParams,
});
}
/**
* No description
*
* @tags Account
* @name AccountControllerGetChargeRewardList
* @summary Get charge reward list
* @request GET:/v1/accounts/charge-reward
* @secure
*/
export async function accountControllerGetChargeRewardList(configParams: RequestParams = {}): Promise<any> {
return request({
url: `/v1/accounts/charge-reward`,
method: "GET",
...configParams,
});
}
/**
* No description
*
Expand All @@ -70,3 +133,56 @@ export async function accountControllerWechatNotify(
...configParams,
});
}
/**
* No description
*
* @tags Account
* @name AccountControllerGiftCode
* @summary Use a gift code
* @request POST:/v1/accounts/gift-code
* @secure
*/
export async function accountControllerGiftCode(data: UseGiftCodeDto, configParams: RequestParams = {}): Promise<any> {
return request({
url: `/v1/accounts/gift-code`,
method: "POST",
data: data,
...configParams,
});
}
/**
* No description
*
* @tags Account
* @name AccountControllerInviteCode
* @summary get a invite code
* @request GET:/v1/accounts/invite-code
* @secure
*/
export async function accountControllerInviteCode(configParams: RequestParams = {}): Promise<any> {
return request({
url: `/v1/accounts/invite-code`,
method: "GET",
...configParams,
});
}
/**
* No description
*
* @tags Account
* @name AccountControllerInviteCodeProfit
* @summary get invite code profit
* @request GET:/v1/accounts/invite-profit
* @secure
*/
export async function accountControllerInviteCodeProfit(
query: AccountControllerInviteCodeProfitParams,
configParams: RequestParams = {},
): Promise<any> {
return request({
url: `/v1/accounts/invite-profit`,
method: "GET",
params: query,
...configParams,
});
}
59 changes: 59 additions & 0 deletions cli/src/api/v1/application.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { request, RequestParams } from "../../util/request";
import {
ApplicationControllerFindOneData,
BindCustomDomainDto,
CreateApplicationDto,
CreateDependencyDto,
CreateEnvironmentDto,
Expand Down Expand Up @@ -145,6 +146,64 @@ export async function applicationControllerUpdateBundle(
...configParams,
});
}
/**
* No description
*
* @tags Application
* @name ApplicationControllerBindDomain
* @summary Bind custom domain to application
* @request PATCH:/v1/applications/{appid}/domain
* @secure
*/
export async function applicationControllerBindDomain(
appid: string,
data: BindCustomDomainDto,
configParams: RequestParams = {},
): Promise<any> {
return request({
url: `/v1/applications/${appid}/domain`,
method: "PATCH",
data: data,
...configParams,
});
}
/**
* No description
*
* @tags Application
* @name ApplicationControllerRemove
* @summary Remove custom domain of application
* @request DELETE:/v1/applications/{appid}/domain
* @secure
*/
export async function applicationControllerRemove(appid: string, configParams: RequestParams = {}): Promise<any> {
return request({
url: `/v1/applications/${appid}/domain`,
method: "DELETE",
...configParams,
});
}
/**
* No description
*
* @tags Application
* @name ApplicationControllerCheckResolved
* @summary Check if domain is resolved
* @request POST:/v1/applications/{appid}/domain/resolved
* @secure
*/
export async function applicationControllerCheckResolved(
appid: string,
data: BindCustomDomainDto,
configParams: RequestParams = {},
): Promise<any> {
return request({
url: `/v1/applications/${appid}/domain/resolved`,
method: "POST",
data: data,
...configParams,
});
}
/**
* No description
*
Expand Down
60 changes: 12 additions & 48 deletions cli/src/api/v1/authentication.ts
Original file line number Diff line number Diff line change
@@ -1,49 +1,16 @@
import { request, RequestParams } from "../../util/request";
import {
BindPhoneDto,
BindUsernameDto,
CreatePATDto,
PasswdCheckDto,
PasswdResetDto,
PasswdSigninDto,
PasswdSignupDto,
Pat2TokenDto,
PhoneSigninDto,
SendEmailCodeDto,
SendPhoneCodeDto,
} from "./data-contracts";

/**
* No description
*
* @tags Authentication
* @name AuthControllerPat2Token
* @summary Get user token by PAT
* @request POST:/v1/auth/pat2token
*/
export async function authControllerPat2Token(data: Pat2TokenDto, configParams: RequestParams = {}): Promise<any> {
return request({
url: `/v1/auth/pat2token`,
method: "POST",
data: data,
...configParams,
});
}
/**
* No description
*
* @tags Authentication
* @name AuthControllerGetProfile
* @summary Get current user profile
* @request GET:/v1/auth/profile
* @secure
*/
export async function authControllerGetProfile(configParams: RequestParams = {}): Promise<any> {
return request({
url: `/v1/auth/profile`,
method: "GET",
...configParams,
});
}
/**
* No description
*
Expand Down Expand Up @@ -171,16 +138,16 @@ export async function authenticationControllerGetProviders(configParams: Request
* No description
*
* @tags Authentication
* @name AuthenticationControllerBindPhone
* @summary Bind username
* @request POST:/v1/auth/bind/phone
* @name AuthenticationControllerPat2Token
* @summary Get user token by PAT
* @request POST:/v1/auth/pat2token
*/
export async function authenticationControllerBindPhone(
data: BindPhoneDto,
export async function authenticationControllerPat2Token(
data: Pat2TokenDto,
configParams: RequestParams = {},
): Promise<any> {
return request({
url: `/v1/auth/bind/phone`,
url: `/v1/auth/pat2token`,
method: "POST",
data: data,
...configParams,
Expand All @@ -190,16 +157,13 @@ export async function authenticationControllerBindPhone(
* No description
*
* @tags Authentication
* @name AuthenticationControllerBindUsername
* @summary Bind username
* @request POST:/v1/auth/bind/username
* @name EmailControllerSendCode
* @summary Send email verify code
* @request POST:/v1/auth/email/code
*/
export async function authenticationControllerBindUsername(
data: BindUsernameDto,
configParams: RequestParams = {},
): Promise<any> {
export async function emailControllerSendCode(data: SendEmailCodeDto, configParams: RequestParams = {}): Promise<any> {
return request({
url: `/v1/auth/bind/username`,
url: `/v1/auth/email/code`,
method: "POST",
data: data,
...configParams,
Expand Down
Loading

0 comments on commit 8c68089

Please sign in to comment.