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

Automatic database upgrades upon services start-up #7162

Closed
wants to merge 5 commits into from

Conversation

zachliu
Copy link
Contributor

@zachliu zachliu commented Sep 16, 2024

What type of PR is this?

  • Refactor
  • Feature
  • Bug Fix
  • New Query Runner (Data Source)
  • New Alert Destination
  • Other

Description

Automatically upgrade the database upon services start-up. So that we don't need to do it manually using cli tools on the server.

I started the discussion #7005 on automated db migration mechanisms.

Further discussing: #7161 (comment)

How is this tested?

  • Unit tests (pytest, jest)
  • E2E Tests (Cypress)
  • Manually
  • N/A

Related Tickets & Documents

Mobile & Desktop Screenshots/Recordings (if there are UI changes)

@justinclift
Copy link
Member

Ahhh. This looks like it's causing a CI failure by attempting a database upgrade even before the database has been initialised.

@zachliu Are you ok to investigate and get it working? 😄

@zachliu
Copy link
Contributor Author

zachliu commented Sep 17, 2024

@justinclift we probably need a "wait" in ci.yml between these two commands

yarn cypress start -- --skip-db-seed
docker compose run cypress yarn cypress db-seed

do you prefer a blunt sleep 35 or a smarter .ci/wait-for-it.sh localhost:5001 --strict --timeout=35 -- echo "Server is ready."?

@justinclift
Copy link
Member

Hmmm, I wonder why we're skipping the database seed on one line, then running it manually on the next line? At some point I probably knew the answer to that. 😉

That being said, of your two options we should probably take the smarter 😄 approach and wait for the previous step to actually be complete.

@zachliu
Copy link
Contributor Author

zachliu commented Sep 17, 2024

actually, redash has been using a simple sleep in the ci.yml file:

docker compose up -d
sleep 10
- name: Create Test Database

i figure i'll just keep it simple and consistent with the existing code 😁

dumb question: i'll need another PR to update the CI right? otherwise it won't take effect

@gaecoli
Copy link
Member

gaecoli commented Sep 18, 2024

Is this change too dangerous?

@justinclift
Copy link
Member

Is this change too dangerous?

In theory (!) it shouldn't be, at least for not-big-version-jumps (of Redash version).

People trying to run the development code directly against a Redash database from prior-to-version-10 might have issues though (am guessing).

But that would be a very unexpected situation for someone to try unless intentionally getting creative for some reason. 😉

@justinclift
Copy link
Member

i figure i'll just keep it simple and consistent with the existing code 😁

No worries.

dumb question: i'll need another PR to update the CI right? otherwise it won't take effect

Nah. In theory the CI runs from the state of the repo as it is presented by the PR itself.

ie it'll make a git clone -b [PR branch] onto the chosen CI server and then run the CI from the files there.

At least, that's my present understanding of things.

Does that help? 😄

@gaecoli
Copy link
Member

gaecoli commented Sep 18, 2024

Is this change too dangerous?

In theory (!) it shouldn't be, at least for not-big-version-jumps (of Redash version).

People trying to run the development code directly against a Redash database from prior-to-version-10 might have issues though (am guessing).

But that would be a very unexpected situation for someone to try unless intentionally getting creative for some reason. 😉

OK!

@zachliu
Copy link
Contributor Author

zachliu commented Sep 18, 2024

i figure i'll just keep it simple and consistent with the existing code 😁

No worries.

dumb question: i'll need another PR to update the CI right? otherwise it won't take effect

Nah. In theory the CI runs from the state of the repo as it is presented by the PR itself.

ie it'll make a git clone -b [PR branch] onto the chosen CI server and then run the CI from the files there.

At least, that's my present understanding of things.

Does that help? 😄

interesting, then it's very odd that the sleep 30 is ineffective and didn't show up in the log at all 🤔

yarn cypress start -- --skip-db-seed
sleep 30
docker compose run cypress yarn cypress db-seed

@justinclift
Copy link
Member

Well, that's weird then. 😕

Maybe do some test PR's in a different fork or something along those lines?

@zachliu zachliu closed this Sep 18, 2024
@zachliu zachliu deleted the automatic-database-upgrades branch September 18, 2024 15:43
@zachliu
Copy link
Contributor Author

zachliu commented Sep 18, 2024

did some tests in my own fork and found the problem(s):

  1. when updating the .github/workflows/ci.yml, the changes don't take effect until they are merged to master (they will be effective for future PRs)
  2. the issue is not only because we need a sleep between these two commands
    yarn cypress start -- --skip-db-seed
    docker compose run cypress yarn cypress db-seed
    
    but also we are upgrading the db before creating it
    function startServer() {
    console.log("Starting the server...");
    execSync("docker compose -p cypress up -d", { stdio: "inherit" });
    execSync("docker compose -p cypress run server create_db", { stdio: "inherit" });
    }

opened two new PRs:

  1. wait for the db init & upgrade #7167
  2. Automatic database upgrades #7166

@justinclift
Copy link
Member

the changes don't take effect until they are merged to master

Cool. 😄

Heh Heh Heh, I really thought it was whatever the state of the PR branch was that controlled it. But something every day I guess. 😄

we are upgrading the db before creating it

Makes sense. Not a race condition then, just an order-of-operation thing.

Good stuff @zachliu, I'll take a look at those when I'm at the co-working space later on today. 😁

@justinclift
Copy link
Member

I'll take a look at those when I'm at the co-working space later on today.

It's going to have to be tomorrow instead. Today I went through the investigation of broken embeds instead (finding a good enough workaround), and now I'm mentally brain drained.

I've finished the embeds investigation now though, so this will be the first thing to look at tomorrow (unless something urgent pops up overnight). 😄

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.

3 participants