Skip to content

Commit

Permalink
Round integers to avoid error on Postgres
Browse files Browse the repository at this point in the history
  • Loading branch information
cdauth committed Nov 15, 2023
1 parent f456da2 commit 9e2d259
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 6 deletions.
36 changes: 32 additions & 4 deletions server/src/database/line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,30 @@ export default class DatabaseLines {
width : { type: DataTypes.INTEGER.UNSIGNED, allowNull: false, defaultValue: 4, validate: { min: 1 } },
name : { type: DataTypes.TEXT, allowNull: true, get: function(this: LineModel) { return this.getDataValue("name") || "Untitled line"; } },
distance : { type: DataTypes.FLOAT(24, 2).UNSIGNED, allowNull: true },
time : { type: DataTypes.INTEGER.UNSIGNED, allowNull: true },
ascent : { type: DataTypes.INTEGER.UNSIGNED, allowNull: true },
descent : { type: DataTypes.INTEGER.UNSIGNED, allowNull: true },
time : {
type: DataTypes.INTEGER.UNSIGNED,
allowNull: true,
set: function(this: LineModel, v: number | null) {
// Round number to avoid integer column error in Postgres
this.setDataValue("time", v != null ? Math.round(v) : v);
}
},
ascent : {
type: DataTypes.INTEGER.UNSIGNED,
allowNull: true,
set: function(this: LineModel, v: number | null) {
// Round number to avoid integer column error in Postgres
this.setDataValue("ascent", v != null ? Math.round(v) : v);
}
},
descent : {
type: DataTypes.INTEGER.UNSIGNED,
allowNull: true,
set: function(this: LineModel, v: number | null) {
// Round number to avoid integer column error in Postgres
this.setDataValue("descent", v != null ? Math.round(v) : v);
}
},
top: getLatType(),
bottom: getLatType(),
left: getLonType(),
Expand Down Expand Up @@ -120,7 +141,14 @@ export default class DatabaseLines {
pos: getPosType(),
zoom: { type: DataTypes.INTEGER.UNSIGNED, allowNull: false, validate: { min: 1, max: 20 } },
idx: { type: DataTypes.INTEGER.UNSIGNED, allowNull: false },
ele: { type: DataTypes.INTEGER, allowNull: true }
ele: {
type: DataTypes.INTEGER,
allowNull: true,
set: function(this: LinePointModel, v: number | null) {
// Round number to avoid integer column error in Postgres
this.setDataValue("ele", v != null ? Math.round(v) : v);
}
}
}, {
sequelize: this._db._conn,
indexes: [
Expand Down
9 changes: 8 additions & 1 deletion server/src/database/marker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,14 @@ export default class DatabaseMarkers {
size : { type: DataTypes.INTEGER.UNSIGNED, allowNull: false, defaultValue: 25, validate: { min: 15 } },
symbol : { type: DataTypes.TEXT, allowNull: true },
shape : { type: DataTypes.TEXT, allowNull: true },
ele: { type: DataTypes.INTEGER, allowNull: true }
ele: {
type: DataTypes.INTEGER,
allowNull: true,
set: function(this: MarkerModel, v: number | null) {
// Round number to avoid integer column error in Postgres
this.setDataValue("ele", v != null ? Math.round(v) : v);
}
}
}, {
sequelize: this._db._conn,
// pos index is created in migration
Expand Down
9 changes: 8 additions & 1 deletion server/src/database/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,14 @@ export default class DatabaseRoutes {
pos: getPosType(),
zoom: { type: DataTypes.INTEGER.UNSIGNED, allowNull: false, validate: { min: 1, max: 20 } },
idx: { type: DataTypes.INTEGER.UNSIGNED, allowNull: false },
ele: { type: DataTypes.INTEGER, allowNull: true }
ele: {
type: DataTypes.INTEGER,
allowNull: true,
set: function(this: RoutePointModel, v: number | null) {
// Round number to avoid integer column error in Postgres
this.setDataValue("ele", v != null ? Math.round(v) : v);
}
}
}, {
sequelize: this._db._conn,
indexes: [
Expand Down

0 comments on commit 9e2d259

Please sign in to comment.