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

Introduce Postgres DB Adapter #1157

Merged

Conversation

habdelra
Copy link
Contributor

@habdelra habdelra commented Apr 10, 2024

This PR introduces a postgres DB adapter that has the ability to run migrations. I'm using docker to run postgres which makes it really convenient for running locally on dev's machines as well as CI. With docker there is nothing extra that a dev has to do in order to get postgres running. I'm running postgres on port 5435 for dev and test so if you do happen to have postgres installed natively on your system it wont collide with that. The postgres DB will start automatically as part of running pnpm start:all in packages/realm-server

@habdelra habdelra changed the title Create Postgres DB Adapter Introduce Postgres DB Adapter Apr 10, 2024
Copy link

github-actions bot commented Apr 10, 2024

Test Results

584 tests  ±0   580 ✔️ ±0   8m 28s ⏱️ -14s
    1 suites ±0       4 💤 ±0 
    1 files   ±0       0 ±0 

Results for commit b4063ab. ± Comparison against base commit 9a12651.

♻️ This comment has been updated with latest results.

let result = await adapter.execute(`
SELECT column_name
FROM information_schema.columns
WHERE table_schema = 'public' -- Replace 'public' with the schema name if it's different
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe this comment isn’t needed three times? Or at all, in a test 🤔

Copy link
Contributor Author

@habdelra habdelra Apr 11, 2024

Choose a reason for hiding this comment

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

Copy-pasta from chat gpt—I’ll clean up

}

await migrate({
direction: 'up',
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we also add support for rollbacks by providing direction (up, down) as a param to migrateDb?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So you can run migrations from the command line to go up or down. But when the realm server spins up we don’t want to run migrations down—ever.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(I’ll add docs for running migrations from command line as well as generating the schema file for sql lite as part of the same PR)

prepareTestDB();
});

test('it can connect to the DB and run migrations', async function (assert) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe I am missing something but I don't see how this test exercises migrations?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh I see, the migrations are run in the setup and then this test checks whether the migration succeeded.

Copy link
Contributor

Choose a reason for hiding this comment

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

Are we planning on adding support for having a schema and a seed file, and use that for setting up the test db, as opposed to running all the migrations on setup?

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, the fact we even have a table with columns is because migrations ran.

Yes there will be a schema file that is generated from the db. That’s the next ticket that I’m working on 😉

@habdelra habdelra merged commit a5d6fdf into main Apr 11, 2024
23 checks passed
@delete-merged-branch delete-merged-branch bot deleted the cs-6463-document-and-setup-postgres-for-dev-environments branch April 11, 2024 20:49
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