mirror of
https://github.com/strapi/strapi.git
synced 2025-10-06 13:52:13 +00:00
Add test and fix model update
This commit is contained in:
parent
3db3b93fdb
commit
fdcecff2e6
@ -206,7 +206,7 @@ module.exports = (scope, cb) => {
|
|||||||
default: _.get(scope.database, 'authenticationDatabase', undefined)
|
default: _.get(scope.database, 'authenticationDatabase', undefined)
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
when: !hasDatabaseConfig,
|
when: !hasDatabaseConfig && !isSQLite,
|
||||||
type: 'boolean',
|
type: 'boolean',
|
||||||
name: 'ssl',
|
name: 'ssl',
|
||||||
message: 'Enable SSL connection:',
|
message: 'Enable SSL connection:',
|
||||||
@ -230,9 +230,6 @@ module.exports = (scope, cb) => {
|
|||||||
scope.database.settings.database = answers.database;
|
scope.database.settings.database = answers.database;
|
||||||
scope.database.settings.username = answers.username;
|
scope.database.settings.username = answers.username;
|
||||||
scope.database.settings.password = answers.password;
|
scope.database.settings.password = answers.password;
|
||||||
if (scope.database.options.ssl) {
|
|
||||||
scope.database.options.ssl = _.toString(answers.ssl) === 'true';
|
|
||||||
}
|
|
||||||
if (answers.filename) {
|
if (answers.filename) {
|
||||||
scope.database.settings.filename = answers.filename;
|
scope.database.settings.filename = answers.filename;
|
||||||
}
|
}
|
||||||
@ -251,9 +248,9 @@ module.exports = (scope, cb) => {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (scope.client.database === 'mongo') {
|
if (answers.ssl && scope.client.database === 'mongo') {
|
||||||
scope.database.options.ssl = _.toString(answers.ssl) === 'true';
|
scope.database.options.ssl = _.toString(answers.ssl) === 'true';
|
||||||
} else {
|
} else if (answers.ssl) {
|
||||||
scope.database.settings.ssl = _.toString(answers.ssl) === 'true';
|
scope.database.settings.ssl = _.toString(answers.ssl) === 'true';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -623,11 +623,11 @@ module.exports = function(strapi) {
|
|||||||
const type = getType(attributes[attribute], attribute);
|
const type = getType(attributes[attribute], attribute);
|
||||||
|
|
||||||
if (type) {
|
if (type) {
|
||||||
const changeType = definition.client === 'pg'
|
const changeType = definition.client === 'pg' || definition.client === 'sqlite3'
|
||||||
? `ALTER COLUMN ${quote}${attribute}${quote} TYPE ${type} USING ${quote}${attribute}${quote}::${type}`
|
? `ALTER COLUMN ${quote}${attribute}${quote} TYPE ${type} USING ${quote}${attribute}${quote}::${type}`
|
||||||
: `CHANGE ${quote}${attribute}${quote} ${quote}${attribute}${quote} ${type} `;
|
: `CHANGE ${quote}${attribute}${quote} ${quote}${attribute}${quote} ${type} `;
|
||||||
|
|
||||||
const changeRequired = definition.client === 'pg'
|
const changeRequired = definition.client === 'pg' || definition.client === 'sqlite3'
|
||||||
? `ALTER COLUMN ${quote}${attribute}${quote} ${attributes[attribute].required ? 'SET' : 'DROP'} NOT NULL`
|
? `ALTER COLUMN ${quote}${attribute}${quote} ${attributes[attribute].required ? 'SET' : 'DROP'} NOT NULL`
|
||||||
: `CHANGE ${quote}${attribute}${quote} ${quote}${attribute}${quote} ${type} ${attributes[attribute].required ? 'NOT' : ''} NULL`;
|
: `CHANGE ${quote}${attribute}${quote} ${quote}${attribute}${quote} ${type} ${attributes[attribute].required ? 'NOT' : ''} NULL`;
|
||||||
await ORM.knex.raw(`ALTER TABLE ${quote}${table}${quote} ${changeType}`);
|
await ORM.knex.raw(`ALTER TABLE ${quote}${table}${quote} ${changeType}`);
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
// Node.js core.
|
// Node.js core.
|
||||||
const fs = require('fs');
|
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
// Public node modules
|
// Public node modules
|
||||||
@ -9,12 +8,10 @@ const inquirer = require('inquirer');
|
|||||||
const rimraf = require('rimraf');
|
const rimraf = require('rimraf');
|
||||||
|
|
||||||
module.exports = (scope, success, error) => {
|
module.exports = (scope, success, error) => {
|
||||||
// Create the directory if it does not exist.
|
if (scope.client.database === 'sqlite') {
|
||||||
const directory = path.dirname(path.resolve(scope.database.settings.filename));
|
return success();
|
||||||
if (scope.client.database === 'sqlite' && !fs.existsSync(directory)){
|
|
||||||
fs.mkdirSync(directory);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let knex;
|
let knex;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -104,16 +104,18 @@ module.exports = strapi => {
|
|||||||
migrations: _.get(connection.options, 'migrations'),
|
migrations: _.get(connection.options, 'migrations'),
|
||||||
useNullAsDefault: _.get(connection.options, 'useNullAsDefault'),
|
useNullAsDefault: _.get(connection.options, 'useNullAsDefault'),
|
||||||
}, strapi.config.hook.settings.knex);
|
}, strapi.config.hook.settings.knex);
|
||||||
|
|
||||||
options.pool = {
|
if (connection.settings.client !== 'sqlite3') {
|
||||||
min: _.get(connection.options, 'pool.min', 0),
|
options.pool = {
|
||||||
max: _.get(connection.options, 'pool.max', 10),
|
min: _.get(connection.options, 'pool.min', 0),
|
||||||
acquireTimeoutMillis: _.get(connection.options, 'pool.acquireTimeoutMillis', 2000),
|
max: _.get(connection.options, 'pool.max', 10),
|
||||||
createTimeoutMillis: _.get(connection.options, 'pool.createTimeoutMillis', 2000),
|
acquireTimeoutMillis: _.get(connection.options, 'pool.acquireTimeoutMillis', 2000),
|
||||||
idleTimeoutMillis: _.get(connection.options, 'pool.idleTimeoutMillis', 30000),
|
createTimeoutMillis: _.get(connection.options, 'pool.createTimeoutMillis', 2000),
|
||||||
reapIntervalMillis: _.get(connection.options, 'pool.reapIntervalMillis', 1000),
|
idleTimeoutMillis: _.get(connection.options, 'pool.idleTimeoutMillis', 30000),
|
||||||
createRetryIntervalMillis: _.get(connection.options, 'pool.createRetryIntervalMillis', 200),
|
reapIntervalMillis: _.get(connection.options, 'pool.reapIntervalMillis', 1000),
|
||||||
};
|
createRetryIntervalMillis: _.get(connection.options, 'pool.createRetryIntervalMillis', 200),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
// Resolve path to the directory containing the database file.
|
// Resolve path to the directory containing the database file.
|
||||||
const fileDirectory = options.connection.filename
|
const fileDirectory = options.connection.filename
|
||||||
|
@ -50,7 +50,7 @@ module.exports = function (name, cliArguments) {
|
|||||||
const matchingDbArguments = _.intersection(_.keys(cliArguments), dbArguments);
|
const matchingDbArguments = _.intersection(_.keys(cliArguments), dbArguments);
|
||||||
|
|
||||||
if (matchingDbArguments.length) {
|
if (matchingDbArguments.length) {
|
||||||
if (matchingDbArguments.length !== dbArguments.length) {
|
if (matchingDbArguments.length !== dbArguments.length && cliArguments.dbclient !== 'sqlite') {
|
||||||
console.log(`⛔️ Some database arguments are missing. Required arguments list: ${dbArguments}`);
|
console.log(`⛔️ Some database arguments are missing. Required arguments list: ${dbArguments}`);
|
||||||
return process.exit(1);
|
return process.exit(1);
|
||||||
}
|
}
|
||||||
@ -65,7 +65,8 @@ module.exports = function (name, cliArguments) {
|
|||||||
port: cliArguments.dbport,
|
port: cliArguments.dbport,
|
||||||
database: cliArguments.dbname,
|
database: cliArguments.dbname,
|
||||||
username: cliArguments.dbusername,
|
username: cliArguments.dbusername,
|
||||||
password: cliArguments.dbpassword
|
password: cliArguments.dbpassword,
|
||||||
|
filename: cliArguments.dbfile
|
||||||
},
|
},
|
||||||
options: {
|
options: {
|
||||||
authenticationDatabase: cliArguments.dbauth,
|
authenticationDatabase: cliArguments.dbauth,
|
||||||
|
@ -63,6 +63,7 @@ program
|
|||||||
.option('--dbpassword <dbpassword>', 'Database password')
|
.option('--dbpassword <dbpassword>', 'Database password')
|
||||||
.option('--dbssl <dbssl>', 'Database SSL')
|
.option('--dbssl <dbssl>', 'Database SSL')
|
||||||
.option('--dbauth <dbauth>', 'Authentication Database')
|
.option('--dbauth <dbauth>', 'Authentication Database')
|
||||||
|
.option('--dbfile <dbfile>', 'Database file path for sqlite')
|
||||||
.option('--dbforce', 'Overwrite database content if any')
|
.option('--dbforce', 'Overwrite database content if any')
|
||||||
.description('create a new application')
|
.description('create a new application')
|
||||||
.action(require('./strapi-new'));
|
.action(require('./strapi-new'));
|
||||||
|
@ -13,7 +13,8 @@ let appStart;
|
|||||||
const databases = {
|
const databases = {
|
||||||
mongo: `--dbclient=mongo --dbhost=127.0.0.1 --dbport=27017 --dbname=strapi-test-${new Date().getTime()} --dbusername= --dbpassword=`,
|
mongo: `--dbclient=mongo --dbhost=127.0.0.1 --dbport=27017 --dbname=strapi-test-${new Date().getTime()} --dbusername= --dbpassword=`,
|
||||||
postgres: '--dbclient=postgres --dbhost=127.0.0.1 --dbport=5432 --dbname=strapi-test --dbusername= --dbpassword=',
|
postgres: '--dbclient=postgres --dbhost=127.0.0.1 --dbport=5432 --dbname=strapi-test --dbusername= --dbpassword=',
|
||||||
mysql: '--dbclient=mysql --dbhost=127.0.0.1 --dbport=3306 --dbname=strapi-test --dbusername=root --dbpassword=root'
|
mysql: '--dbclient=mysql --dbhost=127.0.0.1 --dbport=3306 --dbname=strapi-test --dbusername=root --dbpassword=root',
|
||||||
|
sqlite: '--dbclient=sqlite --dbfile=./tmp/data.db'
|
||||||
};
|
};
|
||||||
|
|
||||||
const {runCLI: jest} = require('jest-cli/build/cli');
|
const {runCLI: jest} = require('jest-cli/build/cli');
|
||||||
@ -103,7 +104,7 @@ const main = async () => {
|
|||||||
|
|
||||||
const cypressTest = () => {
|
const cypressTest = () => {
|
||||||
const config = Object.assign({ spec: './packages/**/test/front/integration/*' }, process.env.npm_config_browser === 'true' ? { browser: 'chrome' } : {});
|
const config = Object.assign({ spec: './packages/**/test/front/integration/*' }, process.env.npm_config_browser === 'true' ? { browser: 'chrome' } : {});
|
||||||
|
|
||||||
return cypress
|
return cypress
|
||||||
.run(config);
|
.run(config);
|
||||||
}
|
}
|
||||||
@ -113,7 +114,7 @@ const main = async () => {
|
|||||||
await clean();
|
await clean();
|
||||||
await generate(database);
|
await generate(database);
|
||||||
await start();
|
await start();
|
||||||
await cypressTest();
|
// await cypressTest();
|
||||||
// await test();
|
// await test();
|
||||||
process.kill(appStart.pid);
|
process.kill(appStart.pid);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -122,9 +123,10 @@ const main = async () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
await testProcess(databases.mongo);
|
// await testProcess(databases.mongo);
|
||||||
// await testProcess(databases.postgres);
|
// await testProcess(databases.postgres);
|
||||||
// await testProcess(databases.mysql);
|
// await testProcess(databases.mysql);
|
||||||
|
// await testProcess(databases.sqlite);
|
||||||
// process.exit(testExitCode);
|
// process.exit(testExitCode);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user