@things-factory/shell 6.0.0-alpha.0 → 6.0.0-alpha.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -48,7 +48,7 @@ async function doModePrompt() {
48
48
  : await inquirer.prompt(MODE_QUESTION)
49
49
 
50
50
  process.env.NODE_ENV = answers.mode == 'development' ? 'development' : 'production'
51
- const { appRootPath } = require('@things-factory/env')
51
+ const { config } = require('@things-factory/env')
52
52
 
53
53
  var ormconfig = require('@things-factory/shell/ormconfig')
54
54
 
@@ -56,7 +56,8 @@ async function doModePrompt() {
56
56
  await confirmHost(ormconfig.host)
57
57
  }
58
58
 
59
- migrate(ormconfig)
59
+ const connectionConfig = config.get('ormconfig')
60
+ await migrate(ormconfig, connectionConfig)
60
61
  }
61
62
 
62
63
  async function confirmHost(host) {
@@ -75,19 +76,25 @@ async function confirmHost(host) {
75
76
  ])
76
77
  }
77
78
 
78
- function migrate(ormconfig) {
79
- createConnection({
80
- ...ormconfig,
81
- logging: true
82
- }).then(async (connection, ...others) => {
79
+ async function migrate(ormconfig, connectionConfig) {
80
+ try {
81
+ const connection = await createConnection({
82
+ ...ormconfig,
83
+ ...connectionConfig,
84
+ logging: true
85
+ })
86
+
83
87
  debug('Database connection established')
84
88
 
85
- if ((ormconfig.type == 'sqlite' || ormconfig.type == 'better-sqlite3') && ormconfig.synchronize == false) {
89
+ if ((connectionConfig.type == 'sqlite' || connectionConfig.type == 'better-sqlite3') && connectionConfig.synchronize == false) {
86
90
  await connection.query('PRAGMA foreign_keys=OFF')
87
91
  await connection.synchronize()
88
92
  await connection.query('PRAGMA foreign_keys=ON')
89
93
  }
90
94
 
95
+ const { addDataSource } = require('@things-factory/shell')
96
+ addDataSource('default', connection)
97
+
91
98
  if (flags.undo) {
92
99
  await connection.undoLastMigration()
93
100
  } else {
@@ -96,5 +103,7 @@ function migrate(ormconfig) {
96
103
 
97
104
  await connection.close()
98
105
  debug('Database Migration Done.')
99
- })
106
+ } catch(error) {
107
+ console.error(error)
108
+ }
100
109
  }
@@ -34,10 +34,11 @@ function getRepository(target) {
34
34
  exports.getRepository = getRepository;
35
35
  const databaseInitializer = async () => {
36
36
  try {
37
- const dataSource = await (0, typeorm_1.createConnection)(Object.assign(Object.assign({}, ormconfig), env_1.config.get('ormconfig')));
37
+ const readConnectionConfig = env_1.config.get('ormconfig');
38
+ const dataSource = await (0, typeorm_1.createConnection)(Object.assign(Object.assign({}, ormconfig), readConnectionConfig));
38
39
  addDataSource('default', dataSource);
39
40
  env_1.logger.info('Default DataSource established');
40
- if (ormconfig.type == 'sqlite' && ormconfig.synchronize == false) {
41
+ if (readConnectionConfig.type == 'sqlite' && readConnectionConfig.synchronize == false) {
41
42
  await dataSource.query('PRAGMA foreign_keys=OFF');
42
43
  await dataSource.synchronize();
43
44
  await dataSource.query('PRAGMA foreign_keys=ON');
@@ -1 +1 @@
1
- {"version":3,"file":"database.js","sourceRoot":"","sources":["../../server/initializers/database.ts"],"names":[],"mappings":";;;AAAA,qCAAgF;AAEhF,6CAAiE;AAEjE,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;AAE5B,IAAI,SAAS,CAAA;AACb,IAAI;IACF,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,iBAAW,EAAE,WAAW,CAAC,CAAC,CAAA;CAC5D;AAAC,OAAO,CAAC,EAAE;IACV,SAAS,GAAG,OAAO,CAAC,iCAAiC,CAAC,CAAA;CACvD;AAED,MAAM,WAAW,GAAmC,EAAE,CAAA;AAEtD,SAAgB,aAAa,CAAC,IAAa;IACzC,OAAO,WAAW,CAAC,IAAI,IAAI,SAAS,CAAC,CAAA;AACvC,CAAC;AAFD,sCAEC;AAED,SAAgB,aAAa,CAAC,IAAY,EAAE,UAAsB;IAChE,WAAW,CAAC,IAAI,CAAC,GAAG,UAAU,CAAA;AAChC,CAAC;AAFD,sCAEC;AAED,SAAgB,gBAAgB,CAAC,IAAY;IAC3C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C,CAAC,CAAA;KAChB;AACH,CAAC,CAAA;AAhCY,QAAA,mBAAmB,uBAgC/B","sourcesContent":["import { createConnection, DataSource, EntityTarget, Repository } from 'typeorm'\n\nimport { appRootPath, config, logger } from '@things-factory/env'\n\nconst path = require('path')\n\nvar ormconfig\ntry {\n ormconfig = require(path.resolve(appRootPath, 'ormconfig'))\n} catch (e) {\n ormconfig = require('@things-factory/shell/ormconfig')\n}\n\nconst dataSources: { [name: string]: DataSource } = {}\n\nexport function getDataSource(name?: string): DataSource {\n return dataSources[name || 'default']\n}\n\nexport function addDataSource(name: string, dataSource: DataSource) {\n dataSources[name] = dataSource\n}\n\nexport function removeDataSource(name: string) {\n delete dataSources[name]\n}\n\nexport function getDataSourceNames() {\n return Object.keys(dataSources)\n}\n\nexport function getRepository<X>(target: EntityTarget<X>): Repository<X> {\n return getDataSource('default').getRepository<X>(target)\n}\n\nexport const databaseInitializer = async () => {\n try {\n const dataSource = await createConnection({\n ...ormconfig,\n ...config.get('ormconfig')\n })\n\n addDataSource('default', dataSource)\n\n logger.info('Default DataSource established')\n\n if (ormconfig.type == 'sqlite' && ormconfig.synchronize == false) {\n await dataSource.query('PRAGMA foreign_keys=OFF')\n await dataSource.synchronize()\n await dataSource.query('PRAGMA foreign_keys=ON')\n }\n\n if (config.get('ormconfig4Tx')) {\n const dataSource4Tx = new DataSource({\n ...ormconfig,\n ...config.get('ormconfig4Tx')\n })\n dataSource4Tx.initialize()\n addDataSource('tx', dataSource4Tx)\n\n logger.info('Transaction DataSource established')\n } else {\n addDataSource('tx', dataSource)\n }\n } catch (e) {\n logger.error(e)\n }\n}\n"]}
1
+ {"version":3,"file":"database.js","sourceRoot":"","sources":["../../server/initializers/database.ts"],"names":[],"mappings":";;;AAAA,qCAAgF;AAEhF,6CAAiE;AAEjE,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;AAE5B,IAAI,SAAS,CAAA;AACb,IAAI;IACF,SAAS,GAAG,OAAO,CAAC,IAA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E,CAAA;YAC9B,MAAM,UAAU,CAAC,KAAK,CAAC,wBAAwB,CAAC,CAAA;SACjD;QAED,IAAI,YAAM,CAAC,GAAG,CAAC,cAAc,CAAC,EAAE;YAC9B,MAAM,aAAa,GAAG,IAAI,oBAAU,iCAC/B,SAAS,GACT,YAAM,CAAC,GAAG,CAAC,cAAc,CAAC,EAC7B,CAAA;YACF,aAAa,CAAC,UAAU,EAAE,CAAA;YAC1B,aAAa,CAAC,IAAI,EAAE,aAAa,CAAC,CAAA;YAElC,YAAM,CAAC,IAAI,CAAC,oCAAoC,CAAC,CAAA;SAClD;aAAM;YACL,aAAa,CAAC,IAAI,EAAE,UAAU,CAAC,CAAA;SAChC;KACF;IAAC,OAAO,CAAC,EAAE;QACV,YAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;KAChB;AACH,CAAC,CAAA;AAlCY,QAAA,mBAAmB,uBAkC/B","sourcesContent":["import { createConnection, DataSource, EntityTarget, Repository } from 'typeorm'\n\nimport { appRootPath, config, logger } from '@things-factory/env'\n\nconst path = require('path')\n\nvar ormconfig\ntry {\n ormconfig = require(path.resolve(appRootPath, 'ormconfig'))\n} catch (e) {\n ormconfig = require('@things-factory/shell/ormconfig')\n}\n\nconst dataSources: { [name: string]: DataSource } = {}\n\nexport function getDataSource(name?: string): DataSource {\n return dataSources[name || 'default']\n}\n\nexport function addDataSource(name: string, dataSource: DataSource) {\n dataSources[name] = dataSource\n}\n\nexport function removeDataSource(name: string) {\n delete dataSources[name]\n}\n\nexport function getDataSourceNames() {\n return Object.keys(dataSources)\n}\n\nexport function getRepository<X>(target: EntityTarget<X>): Repository<X> {\n return getDataSource('default').getRepository<X>(target)\n}\n\nexport const databaseInitializer = async () => {\n try {\n const readConnectionConfig = config.get('ormconfig')\n\n const dataSource = await createConnection({\n ...ormconfig,\n ...readConnectionConfig\n })\n\n addDataSource('default', dataSource)\n\n logger.info('Default DataSource established')\n\n if (readConnectionConfig.type == 'sqlite' && readConnectionConfig.synchronize == false) {\n await dataSource.query('PRAGMA foreign_keys=OFF')\n await dataSource.synchronize()\n await dataSource.query('PRAGMA foreign_keys=ON')\n }\n\n if (config.get('ormconfig4Tx')) {\n const dataSource4Tx = new DataSource({\n ...ormconfig,\n ...config.get('ormconfig4Tx')\n })\n dataSource4Tx.initialize()\n addDataSource('tx', dataSource4Tx)\n\n logger.info('Transaction DataSource established')\n } else {\n addDataSource('tx', dataSource)\n }\n } catch (e) {\n logger.error(e)\n }\n}\n"]}