diff --git a/.gitignore b/.gitignore index c2658d7..646ac51 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ +.DS_Store node_modules/ diff --git a/index.js b/index.js index 7ab8443..1908909 100644 --- a/index.js +++ b/index.js @@ -1,3 +1,7 @@ +import Granule, { + init as granuleInit, + associate as granuleAssociate, +} from './models/granule.js'; import L2RasterProduct, { init as l2RasterProductInit, associate as l2RasterProductAssociate, @@ -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, diff --git a/models/granule.js b/models/granule.js new file mode 100644 index 0000000..0c9a4a2 --- /dev/null +++ b/models/granule.js @@ -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', + }); +} diff --git a/models/l2-raster-product.js b/models/l2-raster-product.js index 2023d9c..a60a82a 100644 --- a/models/l2-raster-product.js +++ b/models/l2-raster-product.js @@ -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'; @@ -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, @@ -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', }); } diff --git a/models/product-history.js b/models/product-history.js index 50406e5..b31e41e 100644 --- a/models/product-history.js +++ b/models/product-history.js @@ -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', }); } diff --git a/models/raster-definition.js b/models/raster-definition.js index 5629d7c..209b84b 100644 --- a/models/raster-definition.js +++ b/models/raster-definition.js @@ -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 {} @@ -44,7 +44,7 @@ export function init(sequelize) { * Setup model associations */ export function associate() { - RasterDefinition.hasMany(L2RasterProduct, { - foreignKey: 'definitionID', + RasterDefinition.belongsTo(User, { + foreignKey: 'userId', }); } diff --git a/models/status.js b/models/status.js index d8538f1..3ed3569 100644 --- a/models/status.js +++ b/models/status.js @@ -39,6 +39,6 @@ export function init(sequelize) { */ export function associate() { Status.belongsTo(L2RasterProduct, { - foreignKey: 'productID', + foreignKey: 'productId', }); } diff --git a/models/user.js b/models/user.js index 0b0d9d2..d964db5 100644 --- a/models/user.js +++ b/models/user.js @@ -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, @@ -31,6 +44,6 @@ export function init(sequelize) { export function associate() { User.belongsToMany(L2RasterProduct, { through: 'ProductHistory', - foreignKey: 'requestedByID', + foreignKey: 'requestedById', }); }