Skip to content

Commit

Permalink
Updated schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
joshgarde committed Jul 10, 2023
1 parent 9b6d647 commit 5d20132
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.DS_Store
node_modules/
7 changes: 7 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import Granule, {
init as granuleInit,
associate as granuleAssociate,
} from './models/granule.js';
import L2RasterProduct, {
init as l2RasterProductInit,
associate as l2RasterProductAssociate,
Expand Down Expand Up @@ -27,17 +31,20 @@ export default function init(sequelize) {
userInit(sequelize);
rasterDefinitionInit(sequelize);
l2RasterProductInit(sequelize);
granuleInit(sequelize);
productHistoryInit(sequelize);
statusInit(sequelize);

userAssociate();
rasterDefinitionAssociate();
l2RasterProductAssociate();
granuleAssociate();
productHistoryAssociate();
statusAssociate();
}

export {
Granule,
L2RasterProduct,
ProductHistory,
RasterDefinition,
Expand Down
40 changes: 40 additions & 0 deletions models/granule.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import {DataTypes, Model} from 'sequelize';
import {v4 as uuidv4} from 'uuid';
import L2RasterProduct from './l2-raster-product.js';

/** Granule model */
export default class Granule extends Model {}

/**
* Initialize the Granule model
* @param {Sequelize} sequelize - a sequelize instance
*/
export function init(sequelize) {
Granule.init({
id: {
type: DataTypes.UUID,
defaultValue: uuidv4,
primaryKey: true,
},
timestamp: {
type: DataTypes.DATE,
allowNull: false,
},
uri: {
type: DataTypes.STRING,
allowNull: false,
},
}, {
sequelize,
timestamps: false,
});
}

/**
* Setup model associations
*/
export function associate() {
Granule.belongsTo(L2RasterProduct, {
foreignKey: 'productId',
});
}
26 changes: 20 additions & 6 deletions models/l2-raster-product.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {DataTypes, Model} from 'sequelize';
import {v4 as uuidv4} from 'uuid';
import RasterDefinition from './raster-definition.js';
import Status from './status.js';
import User from './user.js';

Expand Down Expand Up @@ -30,6 +29,24 @@ export function init(sequelize) {
type: DataTypes.INTEGER,
allowNull: false,
},
outputGranuleExtentFlag: {
type: DataTypes.BOOLEAN,
allowNull: false,
},
outputSamplingGridType: {
type: DataTypes.STRING,
allowNull: false,
},
rasterResolution: {
type: DataTypes.INTEGER,
allowNull: false,
},
utmZoneAdjust: {
type: DataTypes.INTEGER,
},
mgrsBandAdjust: {
type: DataTypes.INTEGER,
},
}, {
sequelize,
timestamps: false,
Expand All @@ -40,14 +57,11 @@ export function init(sequelize) {
* Setup model associations
*/
export function associate() {
L2RasterProduct.belongsTo(RasterDefinition, {
foreignKey: 'definitionID',
});
L2RasterProduct.hasMany(Status, {
foreignKey: 'productID',
foreignKey: 'productId',
});
L2RasterProduct.belongsToMany(User, {
through: 'ProductHistory',
foreignKey: 'rasterProductID',
foreignKey: 'rasterProductId',
});
}
4 changes: 2 additions & 2 deletions models/product-history.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ export function init(sequelize) {
*/
export function associate() {
ProductHistory.belongsTo(L2RasterProduct, {
foreignKey: 'rasterProductID',
foreignKey: 'rasterProductId',
});
ProductHistory.belongsTo(User, {
foreignKey: 'requestedByID',
foreignKey: 'requestedById',
});
}
6 changes: 3 additions & 3 deletions models/raster-definition.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {DataTypes, Model} from 'sequelize';
import {v4 as uuidv4} from 'uuid';
import L2RasterProduct from './l2-raster-product.js';
import User from './user.js';

/** RasterDefinition model */
export default class RasterDefinition extends Model {}
Expand Down Expand Up @@ -44,7 +44,7 @@ export function init(sequelize) {
* Setup model associations
*/
export function associate() {
RasterDefinition.hasMany(L2RasterProduct, {
foreignKey: 'definitionID',
RasterDefinition.belongsTo(User, {
foreignKey: 'userId',
});
}
2 changes: 1 addition & 1 deletion models/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ export function init(sequelize) {
*/
export function associate() {
Status.belongsTo(L2RasterProduct, {
foreignKey: 'productID',
foreignKey: 'productId',
});
}
15 changes: 14 additions & 1 deletion models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,19 @@ export function init(sequelize) {
},
username: {
type: DataTypes.STRING,
allowNull: false,
},
email: {
type: DataTypes.STRING,
allowNull: false,
},
firstName: {
type: DataTypes.STRING,
allowNull: false,
},
lastName: {
type: DataTypes.STRING,
allowNull: false,
},
}, {
sequelize,
Expand All @@ -31,6 +44,6 @@ export function init(sequelize) {
export function associate() {
User.belongsToMany(L2RasterProduct, {
through: 'ProductHistory',
foreignKey: 'requestedByID',
foreignKey: 'requestedById',
});
}

0 comments on commit 5d20132

Please sign in to comment.