Skip to content
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

[WIP]: Release assets #1446

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/light-cycles-repair.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@xata.io/client': major
---

Make XataApiClient to use ES Proxies
15 changes: 15 additions & 0 deletions .changeset/pre.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"mode": "pre",
"tag": "next",
"initialVersions": {
"@xata.io/cli": "0.15.3",
"@xata.io/client": "0.28.2",
"@xata.io/codegen": "0.28.2",
"@xata.io/importer": "1.1.3",
"@xata.io/drizzle": "0.0.13",
"@xata.io/kysely": "0.1.13",
"@xata.io/netlify": "0.1.23",
"@xata.io/plugin-client-opentelemetry": "0.2.37"
},
"changesets": []
}
12 changes: 12 additions & 0 deletions .changeset/violet-worms-develop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
'@xata.io/cli': major
'@xata.io/client': major
'@xata.io/codegen': major
'@xata.io/importer': major
'@xata.io/drizzle': major
'@xata.io/kysely': major
'@xata.io/netlify': major
'@xata.io/plugin-client-opentelemetry': major
---

Version 1.0
2 changes: 0 additions & 2 deletions .github/workflows/build-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,6 @@ jobs:
cat << EOF > .changeset/force-canary-build.md
---
'@xata.io/plugin-client-opentelemetry': patch
'@xata.io/plugin-client-cloudflare': patch
'@xata.io/plugin-client-cache': patch
'@xata.io/drizzle': patch
'@xata.io/kysely': patch
'@xata.io/pgroll': patch
Expand Down
42 changes: 40 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GIT_TOKEN }}
run: |
npx changeset version
npx changeset publish
npx changeset pre exit
npx changeset version --snapshot next
npx changeset publish --tag next --no-git-tag

- name: Create Release Pull Request or Publish to npm
uses: changesets/action@v1
Expand All @@ -65,3 +66,40 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GIT_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

release-cli-assets:
name: Release CLI assets
needs: release
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
steps:
- uses: actions/checkout@v3
with:
# This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits
fetch-depth: 0
# This makes the PR pushed to use GITHUB_TOKEN and trigger the checks
persist-credentials: false

- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 8

- name: Use Node.js ${{ steps.config.outputs.NVMRC }}
uses: actions/setup-node@v3
with:
node-version: ${{ steps.config.outputs.NVMRC }}
cache: 'pnpm'

- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Build
run: pnpm build

- name: Release CLI Assets
run: npx changeset version && pnpm run release:cli
env:
MATRIX_OS: ${{ matrix.os }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
9 changes: 9 additions & 0 deletions cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,15 @@
"hooks": {
"init": "./dist/hooks/init/compatibility"
},
"macos": {
"identifier": "com.xata.cli"
},
"deb": {
"identifier": "com.xata.cli"
},
"win": {
"identifier": "com.xata.cli"
},
"dirname": "xata",
"commands": "./dist/commands",
"plugins": [
Expand Down
36 changes: 23 additions & 13 deletions cli/src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ export abstract class BaseCommand<T extends typeof Command> extends Command {
message: 'New workspace name'
});
if (!name) return this.error('No workspace name provided');
const workspace = await xata.api.workspaces.createWorkspace({ data: { name } });
const workspace = await xata.api.workspaces.createWorkspace({ body: { name } });
return workspace.id;
} else if (workspaces.workspaces.length === 1) {
const workspace = workspaces.workspaces[0].id;
Expand Down Expand Up @@ -309,7 +309,9 @@ export abstract class BaseCommand<T extends typeof Command> extends Command {
options: { allowCreate?: boolean } = {}
): Promise<{ name: string; region: string }> {
const xata = await this.getXataClient();
const { databases: dbs = [] } = await xata.api.database.getDatabaseList({ workspace });
const { databases: dbs = [] } = await xata.api.databases.getDatabaseList({
pathParams: { workspaceId: workspace }
});

if (dbs.length > 0) {
const choices = dbs.map((db) => ({
Expand Down Expand Up @@ -355,7 +357,9 @@ export abstract class BaseCommand<T extends typeof Command> extends Command {
} = {}
): Promise<string> {
const xata = await this.getXataClient();
const { branches = [] } = await xata.api.branches.getBranchList({ workspace, region, database });
const { branches = [] } = await xata.api.branch.getBranchList({
pathParams: { workspace, region, dbName: database }
});

const EMPTY_CHOICE = '$empty';
const CREATE_CHOICE = '$create';
Expand Down Expand Up @@ -421,7 +425,7 @@ export abstract class BaseCommand<T extends typeof Command> extends Command {
);
if (!name) return this.error('No database name provided');

const { regions } = await xata.api.database.listRegions({ workspace });
const { regions } = await xata.api.databases.listRegions({ pathParams: { workspaceId: workspace } });
const { region } = await this.prompt(
{
type: 'select',
Expand All @@ -434,7 +438,10 @@ export abstract class BaseCommand<T extends typeof Command> extends Command {
);
if (!region) return this.error('No region selected');

const result = await xata.api.database.createDatabase({ workspace, database: name, data: { region } });
const result = await xata.api.databases.createDatabase({
pathParams: { workspaceId: workspace, dbName: name },
body: { region }
});

return { name: result.databaseName, region };
}
Expand All @@ -455,9 +462,12 @@ export abstract class BaseCommand<T extends typeof Command> extends Command {
});

if (!from) {
await xata.api.branches.createBranch({ workspace, region, database, branch: name });
await xata.api.branch.createBranch({ pathParams: { workspace, region, dbBranchName: `${database}:${name}` } });
} else {
await xata.api.branches.createBranch({ workspace, region, database, branch: name, from });
await xata.api.branch.createBranch({
pathParams: { workspace, region, dbBranchName: `${database}:${name}` },
body: { from }
});
}

return name;
Expand Down Expand Up @@ -566,11 +576,8 @@ export abstract class BaseCommand<T extends typeof Command> extends Command {
async deploySchema(workspace: string, region: string, database: string, branch: string, schema: Schemas.Schema) {
const xata = await this.getXataClient();
const compare = await xata.api.migrations.compareBranchWithUserSchema({
workspace,
region,
database,
branch,
schema
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
body: { schema }
});

if (compare.edits.operations.length === 0) {
Expand All @@ -587,7 +594,10 @@ export abstract class BaseCommand<T extends typeof Command> extends Command {
});
if (!confirm) return this.exit(1);

await xata.api.migrations.applyBranchSchemaEdit({ workspace, region, database, branch, edits: compare.edits });
await xata.api.migrations.applyBranchSchemaEdit({
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
body: { edits: compare.edits }
});
}
}

Expand Down
5 changes: 4 additions & 1 deletion cli/src/commands/branch/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ export default class BranchCreate extends BaseCommand<typeof BranchCreate> {
const { from } = flags;

try {
const result = await xata.api.branches.createBranch({ workspace, region, database, branch, from });
const result = await xata.api.branch.createBranch({
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
body: { from }
});

if (this.jsonEnabled()) return result;

Expand Down
2 changes: 1 addition & 1 deletion cli/src/commands/branch/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default class BranchDelete extends BaseCommand<typeof BranchDelete> {
if (!confirm) return this.exit(1);
if (confirm !== branch) return this.error('The branch name did not match');

await xata.api.branches.deleteBranch({ workspace, region, database, branch });
await xata.api.branch.deleteBranch({ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` } });

if (this.jsonEnabled()) return {};

Expand Down
2 changes: 1 addition & 1 deletion cli/src/commands/branch/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default class BranchList extends BaseCommand<typeof BranchList> {
const { workspace, region, database } = await this.getParsedDatabaseURL(flags.db);

const xata = await this.getXataClient();
const { branches } = await xata.api.branches.getBranchList({ workspace, region, database });
const { branches } = await xata.api.branch.getBranchList({ pathParams: { workspace, region, dbName: database } });

if (this.jsonEnabled()) return branches;

Expand Down
2 changes: 1 addition & 1 deletion cli/src/commands/dbs/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default class DatabasesDelete extends BaseCommand<typeof DatabasesDelete>
if (!confirm) return this.exit(1);
if (confirm !== database) return this.error('The database name did not match');

await xata.api.database.deleteDatabase({ workspace, database });
await xata.api.databases.deleteDatabase({ pathParams: { workspaceId: workspace, dbName: database } });

if (this.jsonEnabled()) return {};

Expand Down
4 changes: 3 additions & 1 deletion cli/src/commands/dbs/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ export default class DatabasesList extends BaseCommand<typeof DatabasesList> {
(await this.getWorkspace());

const xata = await this.getXataClient();
const { databases: dbs = [] } = await xata.api.database.getDatabaseList({ workspace });
const { databases: dbs = [] } = await xata.api.databases.getDatabaseList({
pathParams: { workspaceId: workspace }
});

if (this.jsonEnabled()) return dbs;

Expand Down
5 changes: 4 additions & 1 deletion cli/src/commands/dbs/rename.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ export default class DatabasesRename extends BaseCommand<typeof DatabasesRename>
if (!confirm) return this.exit(1);
if (confirm !== database) return this.error('The database name did not match');

await xata.api.database.renameDatabase({ workspace, database, newName });
await xata.api.databases.renameDatabase({
pathParams: { workspaceId: workspace, dbName: database },
body: { newName }
});

if (this.jsonEnabled()) return {};

Expand Down
71 changes: 0 additions & 71 deletions cli/src/commands/diff/index.ts

This file was deleted.

14 changes: 8 additions & 6 deletions cli/src/commands/import/csv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,10 @@ export default class ImportCSV extends BaseCommand<typeof ImportCSV> {
{ name: table, columns: columns.filter((c) => c.name !== 'id') }
]
};

const { edits } = await xata.api.migrations.compareBranchWithUserSchema({
workspace,
region,
database,
branch: 'main',
schema: newSchema
pathParams: { workspace, region, dbBranchName: `${database}:main` },
body: { schema: newSchema }
});
if (edits.operations.length > 0) {
const destructiveOperations = edits.operations
Expand Down Expand Up @@ -263,7 +261,11 @@ export default class ImportCSV extends BaseCommand<typeof ImportCSV> {
if (!applyMigrations) {
process.exit(1);
}
await xata.api.migrations.applyBranchSchemaEdit({ workspace, region, database, branch, edits });

await xata.api.migrations.applyBranchSchemaEdit({
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
body: { edits }
});
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions cli/src/commands/init/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ export default class Init extends BaseCommand<typeof Init> {
if (this.projectConfig?.codegen?.output) {
const { schema: currentSchema } = await (
await this.getXataClient()
).api.branches.getBranchDetails({ workspace, database, region, branch });
).api.branch.getBranchDetails({ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` } });

const hasTables = currentSchema?.tables && currentSchema?.tables.length > 0;
const hasColumns = currentSchema?.tables.some((t) => t.columns.length > 0);
Expand Down Expand Up @@ -434,7 +434,7 @@ export default class Init extends BaseCommand<typeof Init> {
let retries = 0;
while (retries++ < maxRetries) {
try {
await xata.api.branches.getBranchList({ workspace, region, database });
await xata.api.branch.getBranchList({ pathParams: { workspace, region, dbName: database } });
return;
} catch (err) {
if (err instanceof Error && err.message.includes('Invalid API key')) {
Expand Down
Loading
Loading