Skip to content

Commit

Permalink
feat: add orgUid indexes to primary tables
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelTaylor3D committed Jan 15, 2022
1 parent 3acca55 commit 13054b8
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
run: npm cache verify

- name: install sequelize-cli globally
run: npm i -g sequelize-cli@6.3.0
run: npm i -g sequelize-cli

- name: install cross-env globally
run: npm install -g cross-env
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
data.sqlite3
test.sqlite3
testMirror.sqlite
testMirror.sqlite3

# dependencies
/node_modules
Expand Down
17 changes: 17 additions & 0 deletions migrations/20220115134849-add-orgUid-index.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use strict';

module.exports = {
async up(queryInterface, Sequelize) {
queryInterface.addIndex('Projects', ['orgUid']);
queryInterface.addIndex('Units', ['orgUid']);
},

async down(queryInterface, Sequelize) {
/**
* Add reverting commands here.
*
* Example:
* await queryInterface.dropTable('users');
*/
},
};
8 changes: 4 additions & 4 deletions src/models/units/units.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import rxjs from 'rxjs';

const { Model } = Sequelize;

const virtualColumns = {
const virtualFields = {
unitBlockStart: {
type: Sequelize.VIRTUAL,
get() {
Expand Down Expand Up @@ -48,7 +48,7 @@ const virtualColumns = {
class Unit extends Model {
static changes = new rxjs.Subject();
static defaultColumns = Object.keys(
Object.assign({}, ModelTypes, virtualColumns),
Object.assign({}, ModelTypes, virtualFields),
);

static associate() {
Expand Down Expand Up @@ -102,7 +102,7 @@ class Unit extends Model {
};

// Check if we need to include the virtual field dep
for (const col of Object.keys(virtualColumns)) {
for (const col of Object.keys(virtualFields)) {
if (columns.includes(col)) {
if (!columns.includes('serialNumberBlock')) {
columns.push('serialNumberBlock');
Expand Down Expand Up @@ -231,7 +231,7 @@ class Unit extends Model {
}
}

Unit.init(Object.assign({}, ModelTypes, virtualColumns), {
Unit.init(Object.assign({}, ModelTypes, virtualFields), {
sequelize,
modelName: 'unit',
foreignKey: 'unitId',
Expand Down
Binary file removed testMirror.sqlite3
Binary file not shown.

0 comments on commit 13054b8

Please sign in to comment.