Skip to content

Commit

Permalink
s3: remove PGROWLOCKS extension from db-migrations (#1190)
Browse files Browse the repository at this point in the history
  • Loading branch information
alxndrsn committed Sep 20, 2024
1 parent 7bad314 commit c391be0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,10 @@ CREATE DATABASE jubilant_test WITH OWNER=jubilant ENCODING=UTF8;
\c jubilant_test;
CREATE EXTENSION IF NOT EXISTS CITEXT;
CREATE EXTENSION IF NOT EXISTS pg_trgm;
CREATE EXTENSION IF NOT EXISTS pgrowlocks;
CREATE DATABASE jubilant WITH OWNER=jubilant ENCODING=UTF8;
\c jubilant;
CREATE EXTENSION IF NOT EXISTS CITEXT;
CREATE EXTENSION IF NOT EXISTS pg_trgm;
CREATE EXTENSION IF NOT EXISTS pgrowlocks;
```

If you are using Docker, you may find it easiest to run the database in Docker by running `make run-docker-postgres`.
Expand Down
1 change: 0 additions & 1 deletion lib/model/migrations/20240913-01-add-blob-s3.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
// except according to the terms contained in the LICENSE file.

const up = async (db) => {
await db.raw('CREATE EXTENSION IF NOT EXISTS pgrowlocks');
await db.raw(`CREATE TYPE S3_UPLOAD_STATUS AS ENUM ('pending', 'uploaded', 'failed')`);
await db.raw(`
ALTER TABLE blobs
Expand Down
22 changes: 19 additions & 3 deletions lib/task/s3.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,25 @@ const assertEnabled = s3 => {

const getCount = withContainer(({ s3, Blobs }) => async status => {
assertEnabled(s3);
const count = await Blobs.s3CountByStatus(status);
console.log(count);
return count; // just for testing
try {
const count = await Blobs.s3CountByStatus(status);
console.log(count);
return count; // just for testing
} catch (err) {
if (err.code === '42883' && err.message === 'function pgrowlocks(unknown) does not exist') {
console.error(`
Error: cannot count blobs by status due to missing PostgreSQL extension: PGROWLOCKS.
To install this extension, execute the following query in your PostgreSQL instance:
CREATE EXTENSION IF NOT EXISTS pgrowlocks;
`);
process.exit(1);
} else {
throw err;
}
}
});

const setFailedToPending = withContainer(({ s3, Blobs }) => async () => {
Expand Down

0 comments on commit c391be0

Please sign in to comment.