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

fix(onboarding): add more allowed dialect #611

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/services/projects/create/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,15 @@ export function getDialect(options: ProjectCreateOptions): ProjectCreateOptions[
const { databaseDialect: dialect, databaseConnectionURL: url } = options;

if (dialect) return dialect;
if (url?.startsWith('postgres://')) return 'postgres';
if (url?.startsWith('mssql://')) return 'mssql';
if (url?.startsWith('mongodb')) return 'mongodb';
if (url?.startsWith('mysql://') || url?.startsWith('mariadb://')) return 'mysql';

if (!url) return null;

const [, extractedDialect] = /(.*):\/\//.exec(url);

if (['mysql2', 'mysql', 'mariadb'].includes(extractedDialect)) return 'mysql';
if (['mssql', 'tedious'].includes(extractedDialect)) return 'mssql';
if (['pg', 'postgres', 'postgresql'].includes(extractedDialect)) return 'postgres';
if (extractedDialect === 'mongodb') return 'mongodb';

return null;
}
Expand Down
19 changes: 3 additions & 16 deletions src/services/schema/update/database.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const { getDialect } = require('../../projects/create/options');

class Database {
constructor({ assertPresent, mongodb, Sequelize, terminator }) {
assertPresent({
Expand Down Expand Up @@ -27,22 +29,7 @@ class Database {

// eslint-disable-next-line class-methods-use-this
getDialect(dbConnectionUrl, dbDialect) {
if (dbConnectionUrl) {
if (dbConnectionUrl.startsWith('postgres://')) {
return 'postgres';
}
if (dbConnectionUrl.startsWith('mysql://')) {
return 'mysql';
}
if (dbConnectionUrl.startsWith('mssql://')) {
return 'mssql';
}
// NOTICE: For MongoDB can be "mongodb://" or "mongodb+srv://"
if (dbConnectionUrl.startsWith('mongodb')) {
return 'mongodb';
}
}
return dbDialect;
return getDialect({ databaseConnectionURL: dbConnectionUrl, databaseDialect: dbDialect });
}

connectToMongodb(options, isSSL) {
Expand Down
1 change: 1 addition & 0 deletions test/commands/projects/create/nosql.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ describe('projects:create:nosql', () => {
databaseUser: '',
databasePassword: '',
databaseSSL: false,
databaseDialect: 'mongodb',
},
},
],
Expand Down
4 changes: 2 additions & 2 deletions test/services/database.unit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ describe('services > database', () => {
});

describe('and no dialect is provided', () => {
it('should return undefined', () => {
it('should return null', () => {
expect.assertions(1);
expect(database.getDialect()).toBeUndefined();
expect(database.getDialect()).toBeNull();
});
});
});
Expand Down