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

chore: adding extra migration to sqlite and improving error message #3240

Merged
merged 3 commits into from
Jan 16, 2025

Conversation

gabrielmer
Copy link
Contributor

@gabrielmer gabrielmer commented Jan 14, 2025

Description

Waku Archive with sqlite was broken, as our table required a storedAt column being not null, and we are not using that column anymore, so insert statements were failing.

The tests didn't catch the issue because migrations weren't executed before the tests, so the tests were run with a db schema that wasn't the one our nodes were using in practice.

Fixed issue executing insert statements and modified tests in order to catch similar issues in the future

Changes

  • added migration script for sqlite's Waku Archive that replaces the storedAt column with timestamp
  • start running migrations before tests, so tests are executed with correct db schema
  • improved error message

Issue

#3236

Copy link

github-actions bot commented Jan 14, 2025

You can find the image built from this PR at

quay.io/wakuorg/nwaku-pr:3240

Built from 8b6a435

Comment on lines +1 to +3
ALTER TABLE message DROP COLUMN timestamp;

ALTER TABLE message RENAME COLUMN storedAt TO timestamp;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copying the following migration we do for Postgres:

-- we can drop the timestamp column because this data is also kept in the storedAt column
ALTER TABLE messages DROP COLUMN timestamp;
-- from now on we are only interested in the message timestamp
ALTER TABLE messages RENAME COLUMN storedAt TO timestamp;

@gabrielmer gabrielmer marked this pull request as ready for review January 14, 2025 18:55
Copy link
Collaborator

@Ivansete-status Ivansete-status left a comment

Choose a reason for hiding this comment

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

Awesome! Thanks for it! 💯

Copy link
Contributor

@NagyZoltanPeter NagyZoltanPeter left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you!

@@ -0,0 +1,3 @@
ALTER TABLE message DROP COLUMN timestamp;

ALTER TABLE message RENAME COLUMN storedAt TO timestamp;
Copy link
Member

Choose a reason for hiding this comment

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

Oh this is cool.
I thought renaming columns in sqlite wasn't possible but required creating a new table with the new column name and migrating the data from the old table to the new one!
Is this a feature that was added recently? (for sure it would be useful even for status since there we do the 'manual' renaming procedure i mentioned).

Copy link
Contributor Author

@gabrielmer gabrielmer Jan 16, 2025

Choose a reason for hiding this comment

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

Good question! Not sure if it's a recent honestly, I just copied it from the migration script we use in postgres and it worked lol

It does seem it's a feature supported by sqlite: https://www.sqlitetutorial.net/sqlite-rename-column/

update: the article does say "SQLite did not support the ALTER TABLE RENAME COLUMN syntax before version 3.25.0."

Copy link
Member

Choose a reason for hiding this comment

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

This was introduced in 2018! wow!

@gabrielmer gabrielmer merged commit bfd60ce into master Jan 16, 2025
10 of 11 checks passed
@gabrielmer gabrielmer deleted the chore-updating-sqlite-archive branch January 16, 2025 15:10
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.

4 participants