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

Feature add pgcrypto ext #795

Merged
merged 2 commits into from
Dec 3, 2024

Conversation

zhuliquan
Copy link
Contributor

@zhuliquan zhuliquan commented Nov 27, 2024

Sometime, we want to use external PG. However, However lower version PG (i.g. 12.16) may not support gen_random_uuid function by default and get following error in migration stage.

{"timestamp":"2024-11-27T10:22:03.165300Z","level":"ERROR","fields":{"message":"Failed to run migrations on PostgresConfig { database_name: \"postgres\", host: \"10.252.176.141\", port: 25432, user: \"postgres\", password: Sensitive(\"JvVQknYlPYhJe2.P_ZAa1\") }: Error { kind: Connection(\"error applying migration V6__add_cluster_table\", Error { kind: Db, cause: Some(DbError { severity: \"ERROR\", parsed_severity: Some(Error), code: SqlState(E42883), message: \"function gen_random_uuid() does not exist\", detail: None, hint: Some(\"No function matches the given name and argument types. You might need to add explicit type casts.\"), position: Some(Original(264)), where_: None, schema: None, table: None, column: None, datatype: None, constraint: None, file: Some(\"parse_func.c\"), line: Some(631), routine: Some(\"ParseFuncOrColumn\") }) }), report: Some(Report { applied_migrations: [] }) }"},"target":"arroyo"}

Here, we must enable pgcrypto extension. So I add below SQL for this case.

CREATE EXTENSION IF NOT EXISTS pgcrypto;

@zhuliquan
Copy link
Contributor Author

It's seems not compatiable with history migration

@zhuliquan zhuliquan closed this Nov 28, 2024
@zhuliquan zhuliquan reopened this Nov 28, 2024
@@ -1,3 +1,4 @@
CREATE EXTENSION IF NOT EXISTS pgcrypto;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This approach won't work unfortunately; migrations are hashed and that's used to determine which ones have been applied. So if we modify an existing migration that will break it for everyone who's already run them.

I think that instead we could run this on the database before invoking the migrations in main:

let report = migrations::migrations::runner()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I have fix it now.

@mwylde mwylde force-pushed the feature-add_pgcrypto_ext branch from d025241 to d0f1b5f Compare December 3, 2024 17:42
Copy link
Member

@mwylde mwylde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@mwylde mwylde enabled auto-merge (squash) December 3, 2024 17:44
@mwylde mwylde merged commit ba2b3e9 into ArroyoSystems:master Dec 3, 2024
3 checks passed
@zhuliquan zhuliquan deleted the feature-add_pgcrypto_ext branch December 4, 2024 03:19
mwylde added a commit that referenced this pull request Dec 9, 2024
mwylde added a commit that referenced this pull request Dec 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants