Skip to content
Merged
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
27 changes: 13 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6

- name: Use Node.js
uses: actions/setup-node@v4
uses: actions/setup-node@v6
with:
node-version-file: '.nvmrc'

Expand Down Expand Up @@ -57,12 +57,12 @@ jobs:
PGPASSWORD: postgres
PGDATABASE: postgres
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6
with:
fetch-depth: 0

- name: Use Node.js
uses: actions/setup-node@v4
uses: actions/setup-node@v6
with:
node-version-file: '.nvmrc'

Expand Down Expand Up @@ -94,7 +94,7 @@ jobs:
run: npm run test -- --coverage

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v5

- name: Print integration environment logs
run: cat docker-compose-logs.txt
Expand All @@ -107,6 +107,7 @@ jobs:
build-publish:
permissions:
contents: write
id-token: write
issues: write
pull-requests: write
runs-on: ubuntu-latest
Expand All @@ -116,26 +117,26 @@ jobs:
steps:
- name: Generate release bot app token
id: generate_token
uses: actions/create-github-app-token@v1
uses: actions/create-github-app-token@v2
with:
app-id: ${{ secrets.HIROSYSTEMS_RELEASE_BOT_ID }}
private-key: ${{ secrets.HIROSYSTEMS_RELEASE_BOT_PEM }}

- uses: actions/checkout@v4
- uses: actions/checkout@v6
with:
token: ${{ secrets.GH_TOKEN || secrets.GITHUB_TOKEN }}
fetch-depth: 0
persist-credentials: false

- name: Get bot user ID
id: bot-user-id
run: |
echo "user-id=$(gh api "/users/${{ steps.generate_token.outputs.app-slug }}[bot]" --jq .id)" >> "$GITHUB_OUTPUT"
env:
GH_TOKEN: ${{ steps.generate_token.outputs.token }}

- uses: actions/setup-node@v4
- uses: actions/setup-node@v6
with:
node-version-file: '.nvmrc'
registry-url: 'https://registry.npmjs.org'

- name: Install deps
run: npm ci --audit=false
Expand All @@ -144,18 +145,16 @@ jobs:
run: npm run build

- name: Semantic Release
uses: cycjimmy/semantic-release-action@v4
uses: cycjimmy/semantic-release-action@b12c8f6015dc215fe37bc154d4ad456dd3833c90 # v6
# Only run on non-PR events or only PRs that aren't from forks
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
env:
GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
SEMANTIC_RELEASE_PACKAGE: ${{ github.event.repository.name }}
GIT_AUTHOR_EMAIL: "${{ steps.bot-user-id.outputs.user-id }}+${{ steps.generate_token.outputs.app-slug }}[bot]@users.noreply.github.com"
GIT_COMMITTER_EMAIL: "${{ steps.bot-user-id.outputs.user-id }}+${{ steps.generate_token.outputs.app-slug }}[bot]@users.noreply.github.com"
with:
semantic_version: 19
extra_plugins: |
@semantic-release/changelog@6.0.3
@semantic-release/git@10.0.1
conventional-changelog-conventionalcommits@6.1.0
conventional-changelog-conventionalcommits@9.1.0
11 changes: 11 additions & 0 deletions src/postgres/__tests__/base-pg-store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,15 @@ describe('BasePgStore', () => {
expect(sqlTransactionContext.getStore()).toBeUndefined();
expect(db.sql).toEqual(obj);
});

test('isConnected returns true when the connection is alive', async () => {
const connected = await db.isConnected();
expect(connected).toBe(true);
});

test('isConnected returns false when the connection is not alive', async () => {
jest.spyOn(db, 'sql').mockRejectedValueOnce(new Error('Connection lost'));
const connected = await db.isConnected();
expect(connected).toBe(false);
});
});
16 changes: 16 additions & 0 deletions src/postgres/base-pg-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,19 @@ export abstract class BasePgStore {
isProdEnv ? this.sql`CONCURRENTLY` : this.sql``
} ${this.sql(viewName)}`;
}

/**
* Checks if the database connection is alive.
* @returns True if connected, false otherwise.
*/
async isConnected(): Promise<boolean> {
try {
await this.sql`SELECT NOW()`;
return true;
} catch (error) {
return false;
}
}
}

/**
Expand Down Expand Up @@ -114,4 +127,7 @@ export abstract class BasePgStoreModule {
async refreshMaterializedView(viewName: string): Promise<void> {
return this.parent.refreshMaterializedView(viewName);
}
async isConnected(): Promise<boolean> {
return this.parent.isConnected();
}
}
Loading