pinstripe 0.16.2 → 0.17.0
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.
package/lib/database/migrator.js
CHANGED
|
@@ -17,7 +17,7 @@ export const Migrator = Class.extend().include({
|
|
|
17
17
|
const migrations = Migration.names.map(name => Migration.for(name)).sort((a, b) => a.schemaVersion - b.schemaVersion);
|
|
18
18
|
for(let i in migrations){
|
|
19
19
|
const migration = migrations[i];
|
|
20
|
-
const isMigrationApplied = this.database.table('pinstripeAppliedMigrations').where({ schemaVersion: migration.schemaVersion }).count() > 0;
|
|
20
|
+
const isMigrationApplied = await this.database.table('pinstripeAppliedMigrations').where({ schemaVersion: migration.schemaVersion }).count() > 0;
|
|
21
21
|
if(!isMigrationApplied){
|
|
22
22
|
if(isDevelopmentEnvironment) console.log(`Applying migration: ${migration.name}`);
|
|
23
23
|
await migration.new(this.database).migrate();
|
package/lib/database/table.js
CHANGED
|
@@ -168,11 +168,12 @@ export const Table = Class.extend().include({
|
|
|
168
168
|
},
|
|
169
169
|
|
|
170
170
|
where(...args){
|
|
171
|
-
if(typeof args[0] == 'string'){
|
|
171
|
+
if(typeof args[0] == 'string' || Array.isArray(args[0])){
|
|
172
172
|
this.expressions.push(args);
|
|
173
173
|
return this;
|
|
174
174
|
}
|
|
175
|
-
const [ scopedBy
|
|
175
|
+
const [ scopedBy ] = args;
|
|
176
|
+
if(typeof scopedBy != 'object') throw new Error(`Invalid argument (0) - expected object, array or string.`);
|
|
176
177
|
const names = Object.keys(scopedBy);
|
|
177
178
|
while(names.length){
|
|
178
179
|
const name = names.shift();
|
|
@@ -183,6 +184,11 @@ export const Table = Class.extend().include({
|
|
|
183
184
|
return this;
|
|
184
185
|
},
|
|
185
186
|
|
|
187
|
+
async tap(fn){
|
|
188
|
+
await fn.call(this);
|
|
189
|
+
return this;
|
|
190
|
+
},
|
|
191
|
+
|
|
186
192
|
orderBy(...args){
|
|
187
193
|
this.orderedBy.push(args);
|
|
188
194
|
return this;
|
|
@@ -11,11 +11,9 @@ Database.include({
|
|
|
11
11
|
const { tenant } = this.options;
|
|
12
12
|
if(tenant && out.info.tenants){
|
|
13
13
|
const { name, host } = tenant;
|
|
14
|
-
|
|
15
|
-
this.
|
|
16
|
-
}
|
|
17
|
-
this.tenant = await out.tenants.where({ host }).first();
|
|
18
|
-
}
|
|
14
|
+
this.tenant = await (await out.tenants.tap(function(){
|
|
15
|
+
this.where('(? = ? or ? = ?)', this.tableReference.createColumnReference('name'), name, this.tableReference.createColumnReference('host'), host);
|
|
16
|
+
})).first();
|
|
19
17
|
}
|
|
20
18
|
return out;
|
|
21
19
|
},
|
|
@@ -10,7 +10,7 @@ export default {
|
|
|
10
10
|
}
|
|
11
11
|
return Database.new(this.context.root.databaseClient, {
|
|
12
12
|
tenant: {
|
|
13
|
-
name: this.initialParams._headers['x-tenant'],
|
|
13
|
+
name: this.initialParams._headers['x-tenant'] || this.initialParams._url.hostname.replace(/\..*$/, ''),
|
|
14
14
|
host: this.initialParams._url.hostname
|
|
15
15
|
}
|
|
16
16
|
})
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "pinstripe",
|
|
4
4
|
"description": "A slick web framework for Node.js.",
|
|
5
|
-
"version": "0.
|
|
5
|
+
"version": "0.17.0",
|
|
6
6
|
"author": "Jody Salt",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"exports": {
|
|
@@ -48,5 +48,5 @@
|
|
|
48
48
|
"tmp": "^0.2.1",
|
|
49
49
|
"unionfs": "^4.4.0"
|
|
50
50
|
},
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "ccfaad0d841d6404b4eec608f8c6e04ce83dcec5"
|
|
52
52
|
}
|