-
Notifications
You must be signed in to change notification settings - Fork 166
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
Open
shubham-padia
wants to merge
3
commits into
boxyhq:main
Choose a base branch
from
shubham-padia:feature/add-postgres-schema-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const DEFAULT_POSTGRES_SCHEMA = 'public'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ const dbObjs: { [key: string]: DatabaseDriver } = {}; | |
const connectionStores: Storable[] = []; | ||
const ttlStores: Storable[] = []; | ||
const ttl = 2; | ||
const non_default_schema = 'non_default'; | ||
|
||
const record1 = { | ||
id: '1', | ||
|
@@ -130,6 +131,12 @@ const dbs = [ | |
...postgresDbConfig, | ||
encryptionKey, | ||
}, | ||
{ | ||
...postgresDbConfig, | ||
postgres: { | ||
schema: non_default_schema, | ||
}, | ||
}, | ||
{ | ||
...mongoDbConfig, | ||
}, | ||
|
@@ -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; | ||
} else { | ||
dbObjs[opts.engine! + (opts.type ? opts.type : '')] = db; | ||
} | ||
|
||
const randomSession = Date.now(); | ||
connectionStores.push(db.store('saml:config:' + randomSession + randomBytes(4).toString('hex'))); | ||
|
@@ -201,15 +212,32 @@ tap.teardown(async () => { | |
}); | ||
|
||
tap.test('dbs', async () => { | ||
// We need this to ensure that the test runs atleast once. | ||
// It is quite easy to skip the test by mistake in the future | ||
// if one of the conditions change and it goes unnoticed. | ||
let has_non_default_postgres_schema_test_ran = false; | ||
for (const idx in connectionStores) { | ||
const connectionStore = connectionStores[idx]; | ||
const ttlStore = ttlStores[idx]; | ||
const dbEngine = dbs[idx].engine!; | ||
let dbType = dbEngine; | ||
let dbType = dbEngine.toString(); | ||
if (dbs[idx].type) { | ||
dbType += ': ' + dbs[idx].type; | ||
} | ||
|
||
tap.test('Test non default postgres schema', (t) => { | ||
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 commentThe 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 |
||
], | ||
non_default_schema | ||
); | ||
} | ||
has_non_default_postgres_schema_test_ran = true; | ||
t.end(); | ||
}); | ||
|
||
tap.test('put(): ' + dbType, async () => { | ||
await connectionStore.put( | ||
record1.id, | ||
|
@@ -527,4 +555,9 @@ tap.test('dbs', async () => { | |
await value.close(); | ||
} | ||
}); | ||
|
||
tap.test('Ensure that the test for non default postgres schema has ran atleast once', (t) => { | ||
t.same(has_non_default_postgres_schema_test_ran, true); | ||
t.end(); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.