-
Notifications
You must be signed in to change notification settings - Fork 164
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 postgres schema support #2540
base: main
Are you sure you want to change the base?
Feature/add postgres schema support #2540
Conversation
Fixes boxyhq#1818. This commit adds postgres schema support to the app logic. The dev environment uses synchronize function to create tables, and does not run the explicit migrations. We will add schema support for production in the next commit.
- Unlike dev environment, schema will not be created if it does not exist and instead will throw an error. The dev should also make sure that they have sufficient usage and create priviliges on the schema. - The env variables in .env file will not be picked up by the migration script. Please export them explicitly. - The migration script inside migration/sql was copied to the postgres directory to accomodate the postgres schema. That migration will now not run for both mssql and postgres. - You might notice that we set the schema in the dataSource from the env variable and we still modify the SQL strings in migrations file to include schema name. This is because queryRunner when running raw sql commands runs the commands directly without modification. But we still need to set the schema because TypeORM does a select operation on `_jackson_migrations` table and the schema name is needed in the dataSource for that.
ad3c59e
to
3aac072
Compare
@@ -188,7 +195,11 @@ tap.before(async () => { | |||
for (const idx in dbs) { | |||
const opts = dbs[idx]; | |||
const db = await DB.new(opts, true); | |||
dbObjs[opts.engine! + (opts.type ? opts.type : '')] = db; | |||
if (opts.type === 'postgres' && opts['schema'] === non_default_schema) { | |||
dbObjs[opts['schema'] + opts.engine! + (opts.type ? opts.type : '')] = db; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We needed a different DB object for the non default schema, that is why this condition. Previously, the previous db would have been overwritten by the new one.
if (dbType === 'sql: postgres' && dbs[idx].postgres?.schema === non_default_schema) { | ||
t.same( | ||
connectionStore['db']['db']['dataSource']['createQueryBuilder']()['connection']['options'][ | ||
'schema' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not the cleanest solution, but since we want to expose a limited number of methods in DatabaseDriver, we needed to access private members of the class to test our changes
None of the test suites has ran, I think I'll need someone's help to trigger them! |
@shubham-padia Should not modify existing migration scripts, that will break all existing migrations. We'll need separate migrations scripts for custom schema. |
Error: [WebServer] [next-auth][error][NO_SECRET]
https://next-auth.js.org/errors#no_secret Please define a `secret` in production. MissingSecret [MissingSecretError]: Please define a `secret` in production.
at assertConfig (/home/runner/work/jackson/jackson/.next/standalone/node_modules/next-auth/core/lib/assert.js:42:12)
at AuthHandler (/home/runner/work/jackson/jackson/.next/standalone/node_modules/next-auth/core/index.js:77:52)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async NextAuthApiHandler (/home/runner/work/jackson/jackson/.next/standalone/node_modules/next-auth/next/index.js:22:19)
at async NextAuth._args$ (/home/runner/work/jackson/jackson/.next/standalone/node_modules/next-auth/next/index.js:[108](https://github.com/boxyhq/jackson/actions/runs/8582034943/job/23522024213?pr=2540#step:17:109):14)
at async K (/home/runner/work/jackson/jackson/.next/standalone/node_modules/next/dist/compiled/next-server/pages-api.runtime.prod.js:20:16545)
at async U.render (/home/runner/work/jackson/jackson/.next/standalone/node_modules/next/dist/compiled/next-server/pages-api.runtime.prod.js:20:16981)
at async NextNodeServer.runApi (/home/runner/work/jackson/jackson/.next/standalone/node_modules/next/dist/server/next-server.js:554:9)
at async NextNodeServer.handleCatchallRenderRequest (/home/runner/work/jackson/jackson/.next/standalone/node_modules/next/dist/server/next-server.js:266:37)
at async NextNodeServer.handleRequestImpl (/home/runner/work/jackson/jackson/.next/standalone/node_modules/next/dist/server/base-server.js:791:17) {
code: 'NO_SECRET'
} |
@shubham-padia I believe TypeORM uses a checksum on the migrations files so modifying it will result in the migration failing. Would be good to verify this by running the old migration files and then running yours again to see if it works. Github Actions will not expose our secrets to this PR (because it's external). We'll check if we can override this. |
@deepakprabhakara I checked the source code and this is how TypeOrm loads executed migrations, it makes a query to the migrations table which in our case is I also manually verified it using the following steps:
In the last step, no migrations were ran. You can check my terminal output below. Terminal output
|
@deepakprabhakara just checking in on the review status for this PR :) ! |
@shubham-padia We will get around to this shortly. Need to test it out fully before we push it through. |
@niwsa Any update here? |
What does this PR do?
Fixes #1818
Changes + decisions:
First commit:
Second commit:
_jackson_migrations
table and the schema name is needed in the dataSource for that.Type of change
How should this be tested?
I have added tests for the dev environment to cover the first commit. For the second commit, I couldn't find any automated tests, so please test this manually
Question:
Checklist: