Skip to content

Commit

Permalink
Merge pull request #11 from bytebase/migration
Browse files Browse the repository at this point in the history
feat: add user table
  • Loading branch information
tianzhou authored Mar 14, 2024
2 parents 7fd8214 + 7e9e6c1 commit 19b56cc
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 28 deletions.
28 changes: 23 additions & 5 deletions .github/actions/check-issue-status/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,13 +280,13 @@ function run() {
else {
// This means the PR content is different from the Bytebase issue content.
// It could be that Bytebase issue content is manually changed by someone.
core.error(`Migration mismatch for ${matchedChange.file} with task ${task.title} under stage ${stage.title}`);
core.error((0, diff_1.createPatch)('difference', matchedChange.content, actualRolloutContent));
core.setFailed(`Migration mismatch for ${matchedChange.file} with task ${task.title} under stage ${stage.title}`);
core.setFailed((0, diff_1.createPatch)('difference', matchedChange.content, actualRolloutContent, matchedChange.file, task.title));
}
}
else {
// This means Bytebase contains a task not found in the PR
core.error(`Unexpected task ${task.title} under stage ${stage.title} and content ${actualRolloutContent}`);
core.setFailed(`Unexpected task ${task.title} under stage ${stage.title} and content ${actualRolloutContent}`);
}
}
}
Expand All @@ -301,10 +301,28 @@ function run() {
}
}
}
if (hasMatch) {
core.error(`Migration ${change.file} not found in the rollout`);
if (!hasMatch) {
core.setFailed(`Migration ${change.file} not found in the rollout`);
}
}
// Sample rollout details
//
// [
// {
// "id": "ch-ci-example-pr11-1001",
// "file": "migrations/1001_init.up.sql",
// "content": "CREATE TABLE \"user\" (\n \"id\" SERIAL NOT NULL,\n \"firstName\" character varying NOT NULL,\n \"lastName\" character varying NOT NULL,\n \"age\" integer NOT NULL,\n CONSTRAINT \"PK_cace4a159ff9f2512dd42373760\" PRIMARY KEY (\"id\")\n);",
// "schemaVersion": "1001",
// "status": "DONE"
// },
// {
// "id": "ch-ci-example-pr11-1002",
// "file": "migrations/1002_change.up.sql",
// "content": "ALTER TABLE \"user1\" DROP COLUMN \"age\";\nALTER TABLE \"user1\" ADD \"address\" character varying;\nALTER TABLE \"user1\" ADD \"gender\" character varying NOT NULL;",
// "schemaVersion": "1002",
// "status": "NOT_STARTED"
// }
// ]
core.info("Rollout details:\n" + JSON.stringify(changes, null, 2));
core.setOutput("rollout-details", changes);
}
Expand Down
34 changes: 26 additions & 8 deletions .github/actions/check-issue-status/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ interface Change {
// Thus later we can derive the same id when we want to check the change.
function generateChangeIdAndSchemaVersion(repo: string, pr: string, file: string) : { id: string; version: string} {
// filename should follow yyy/<<version>>_xxxx
const version = path.basename(file).split("_")[0]
// Replace all non-alphanumeric characters with hyphens
return { id: `ch-${repo}-pr${pr}-${version}`.replace(/[^a-zA-Z0-9]/g, '-'), version};
const version = path.basename(file).split("_")[0]
// Replace all non-alphanumeric characters with hyphens
return { id: `ch-${repo}-pr${pr}-${version}`.replace(/[^a-zA-Z0-9]/g, '-'), version};
}

async function run(): Promise<void> {
Expand Down Expand Up @@ -263,12 +263,12 @@ async function run(): Promise<void> {
} else {
// This means the PR content is different from the Bytebase issue content.
// It could be that Bytebase issue content is manually changed by someone.
core.error(`Migration mismatch for ${matchedChange.file} with task ${task.title} under stage ${stage.title}`)
core.error(createPatch('difference', matchedChange.content, actualRolloutContent));
core.setFailed(`Migration mismatch for ${matchedChange.file} with task ${task.title} under stage ${stage.title}`)
core.setFailed(createPatch('difference', matchedChange.content, actualRolloutContent, matchedChange.file, task.title));
}
} else {
// This means Bytebase contains a task not found in the PR
core.error(`Unexpected task ${task.title} under stage ${stage.title} and content ${actualRolloutContent}`)
core.setFailed(`Unexpected task ${task.title} under stage ${stage.title} and content ${actualRolloutContent}`)
}
}
}
Expand All @@ -284,11 +284,29 @@ async function run(): Promise<void> {
}
}
}
if (hasMatch) {
core.error(`Migration ${change.file} not found in the rollout`)
if (!hasMatch) {
core.setFailed(`Migration ${change.file} not found in the rollout`)
}
}

// Sample rollout details
//
// [
// {
// "id": "ch-ci-example-pr11-1001",
// "file": "migrations/1001_init.up.sql",
// "content": "CREATE TABLE \"user\" (\n \"id\" SERIAL NOT NULL,\n \"firstName\" character varying NOT NULL,\n \"lastName\" character varying NOT NULL,\n \"age\" integer NOT NULL,\n CONSTRAINT \"PK_cace4a159ff9f2512dd42373760\" PRIMARY KEY (\"id\")\n);",
// "schemaVersion": "1001",
// "status": "DONE"
// },
// {
// "id": "ch-ci-example-pr11-1002",
// "file": "migrations/1002_change.up.sql",
// "content": "ALTER TABLE \"user1\" DROP COLUMN \"age\";\nALTER TABLE \"user1\" ADD \"address\" character varying;\nALTER TABLE \"user1\" ADD \"gender\" character varying NOT NULL;",
// "schemaVersion": "1002",
// "status": "NOT_STARTED"
// }
// ]
core.info("Rollout details:\n" + JSON.stringify(changes, null, 2))
core.setOutput("rollout-details", changes);
}
Expand Down
9 changes: 3 additions & 6 deletions .github/actions/sql-review/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,10 @@ function run() {
});
const httpStatus = response.status;
if (httpStatus !== 200) {
core.error(`Failed to check SQL file ${file} with response code ${httpStatus}`);
process.exit(1);
throw new Error(`Failed to check SQL file ${file} with response code ${httpStatus}`);
}
const responseData = yield response.json();
core.debug("Advices:" + JSON.stringify(responseData.advices));
core.debug("Reviews:" + JSON.stringify(responseData.advices));
responseData.advices.forEach((advice) => {
const annotation = `::${advice.status} file=${file},line=${advice.line},col=${advice.column},title=${advice.title} (${advice.code})::${advice.content}. https://www.bytebase.com/docs/reference/error-code/advisor#${advice.code}`;
// Emit annotations for each advice
Expand All @@ -111,9 +110,7 @@ function run() {
});
}
if (hasErrorOrWarning) {
core.error("Advice contains ERROR or WARNING violations. Marking for failure.");
// If you want to fail the GitHub Action if any error or warning is found
core.setFailed("SQL check failed due to ERROR or WARNING.");
core.setFailed("Review contains ERROR or WARNING violations. Marking for failure.");
}
}
catch (error) {
Expand Down
9 changes: 3 additions & 6 deletions .github/actions/sql-review/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,13 @@ async function run(): Promise<void> {
const httpStatus = response.status;

if (httpStatus !== 200) {
core.error(`Failed to check SQL file ${file} with response code ${httpStatus}`);
process.exit(1);
throw new Error(`Failed to check SQL file ${file} with response code ${httpStatus}`);
}

const responseData = await response.json();


core.debug("Advices:" + JSON.stringify(responseData.advices));
core.debug("Reviews:" + JSON.stringify(responseData.advices));
responseData.advices.forEach((advice: { status: string; line: any; column: any; title: any; code: any; content: any; }) => {
const annotation = `::${advice.status} file=${file},line=${advice.line},col=${advice.column},title=${advice.title} (${advice.code})::${advice.content}. https://www.bytebase.com/docs/reference/error-code/advisor#${advice.code}`;
// Emit annotations for each advice
Expand All @@ -91,9 +90,7 @@ async function run(): Promise<void> {
}

if (hasErrorOrWarning) {
core.error("Advice contains ERROR or WARNING violations. Marking for failure.");
// If you want to fail the GitHub Action if any error or warning is found
core.setFailed("SQL check failed due to ERROR or WARNING.");
core.setFailed("Review contains ERROR or WARNING violations. Marking for failure.");
}
} catch (error) {
if (error instanceof Error) core.setFailed(error.message);
Expand Down
2 changes: 1 addition & 1 deletion .github/actions/sql-review/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion .github/actions/upsert-issue/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ interface Change {
// Use a deterministic way to generate the change id and schema version.
// Thus later we can derive the same id when we want to check the change.
function generateChangeIdAndSchemaVersion(repo: string, pr: string, file: string) : { id: string; version: string} {
// filename should follow yyy/<<version>>_xxxx
// filename should follow yyy/<<version>>_xxxx
const version = path.basename(file).split("_")[0]
// Replace all non-alphanumeric characters with hyphens
return { id: `ch-${repo}-pr${pr}-${version}`.replace(/[^a-zA-Z0-9]/g, '-'), version};
}


async function run(): Promise<void> {
const githubToken = core.getInput('github-token', { required: true });
const pattern = core.getInput('pattern', { required: true });
Expand Down
2 changes: 1 addition & 1 deletion .github/actions/upsert-issue/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 19b56cc

Please sign in to comment.