Skip to content

Commit 504a898

Browse files
committed
chore: update price field to use Decimal type in database migrations and related code
1 parent 8664eb1 commit 504a898

File tree

5 files changed

+16
-16
lines changed

5 files changed

+16
-16
lines changed

dev-demo/index.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import express from 'express';
2-
import AdminForth from 'adminforth';
2+
import AdminForth, { Filters } from '../adminforth/index.js';
33
import usersResource from "./resources/adminuser.js";
44
import { fileURLToPath } from 'url';
55
import path from 'path';
6-
import { Filters } from 'adminforth';
6+
import { Decimal } from 'decimal.js';
77
import { initApi } from './api.js';
88
import cars_SQLITE_resource from './resources/cars_SL.js';
99
import cars_MyS_resource from './resources/cars_MyS.js';
@@ -202,12 +202,12 @@ if (fileURLToPath(import.meta.url) === path.resolve(process.argv[1])) {
202202
await admin.resource('cars_sl').create({
203203
id: `${i}`,
204204
model: `${FICTIONAL_CAR_BRANDS[Math.floor(Math.random() * FICTIONAL_CAR_BRANDS.length)]} ${FICTIONAL_CAR_MODELS_BY_BRAND[FICTIONAL_CAR_BRANDS[Math.floor(Math.random() * FICTIONAL_CAR_BRANDS.length)]][Math.floor(Math.random() * 4)]}`,
205-
price: (Math.random() * 10000).toFixed(2),
205+
price: Decimal(Math.random() * 10000).toFixed(2),
206206
engine_type: engine_type,
207207
engine_power: engine_type === 'electric' ? null : Math.floor(Math.random() * 400) + 100,
208208
production_year: Math.floor(Math.random() * 31) + 1990,
209209
listed: i % 2 == 0,
210-
mileage: `${Math.floor(Math.random() * 200000)}`,
210+
mileage: Math.floor(Math.random() * 200000),
211211
body_type: BODY_TYPES[Math.floor(Math.random() * BODY_TYPES.length)].value,
212212
});
213213
};
@@ -218,12 +218,12 @@ if (fileURLToPath(import.meta.url) === path.resolve(process.argv[1])) {
218218
await admin.resource('cars_mongo').create({
219219
_id: `${i}`,
220220
model: `${FICTIONAL_CAR_BRANDS[Math.floor(Math.random() * FICTIONAL_CAR_BRANDS.length)]} ${FICTIONAL_CAR_MODELS_BY_BRAND[FICTIONAL_CAR_BRANDS[Math.floor(Math.random() * FICTIONAL_CAR_BRANDS.length)]][Math.floor(Math.random() * 4)]}`,
221-
price: (Math.random() * 10000).toFixed(2),
221+
price: Decimal(Math.random() * 10000).toFixed(2),
222222
engine_type: engine_type,
223223
engine_power: engine_type === 'electric' ? null : Math.floor(Math.random() * 400) + 100,
224224
production_year: Math.floor(Math.random() * 31) + 1990,
225225
listed: i % 2 == 0,
226-
mileage: `${Math.floor(Math.random() * 200000)}`,
226+
mileage: Math.floor(Math.random() * 200000),
227227
body_type: BODY_TYPES[Math.floor(Math.random() * BODY_TYPES.length)].value,
228228
});
229229
};
@@ -235,12 +235,12 @@ if (fileURLToPath(import.meta.url) === path.resolve(process.argv[1])) {
235235
await admin.resource('cars_mysql').create({
236236
id: `${i}`,
237237
model: `${FICTIONAL_CAR_BRANDS[Math.floor(Math.random() * FICTIONAL_CAR_BRANDS.length)]} ${FICTIONAL_CAR_MODELS_BY_BRAND[FICTIONAL_CAR_BRANDS[Math.floor(Math.random() * FICTIONAL_CAR_BRANDS.length)]][Math.floor(Math.random() * 4)]}`,
238-
price: (Math.random() * 10000).toFixed(2),
238+
price: Decimal(Math.random() * 10000).toFixed(2),
239239
engine_type: engine_type,
240240
engine_power: engine_type === 'electric' ? null : Math.floor(Math.random() * 400) + 100,
241241
production_year: Math.floor(Math.random() * 31) + 1990,
242242
listed: i % 2 == 0,
243-
mileage: `${Math.floor(Math.random() * 200000)}`,
243+
mileage: Math.floor(Math.random() * 200000),
244244
body_type: BODY_TYPES[Math.floor(Math.random() * BODY_TYPES.length)].value,
245245
});
246246
};
@@ -252,12 +252,12 @@ if (fileURLToPath(import.meta.url) === path.resolve(process.argv[1])) {
252252
await admin.resource('cars_pg').create({
253253
id: `${i}`,
254254
model: `${FICTIONAL_CAR_BRANDS[Math.floor(Math.random() * FICTIONAL_CAR_BRANDS.length)]} ${FICTIONAL_CAR_MODELS_BY_BRAND[FICTIONAL_CAR_BRANDS[Math.floor(Math.random() * FICTIONAL_CAR_BRANDS.length)]][Math.floor(Math.random() * 4)]}`,
255-
price: (Math.random() * 10000).toFixed(2),
255+
price: Decimal(Math.random() * 10000).toFixed(2),
256256
engine_type: engine_type,
257257
engine_power: engine_type === 'electric' ? null : Math.floor(Math.random() * 400) + 100,
258258
production_year: Math.floor(Math.random() * 31) + 1990,
259259
listed: i % 2 == 0,
260-
mileage: `${Math.floor(Math.random() * 200000)}`,
260+
mileage: Math.floor(Math.random() * 200000),
261261
body_type: BODY_TYPES[Math.floor(Math.random() * BODY_TYPES.length)].value,
262262
});
263263
};
@@ -269,12 +269,12 @@ if (fileURLToPath(import.meta.url) === path.resolve(process.argv[1])) {
269269
await admin.resource('cars_ch').create({
270270
id: `${i}`,
271271
model: `${FICTIONAL_CAR_BRANDS[Math.floor(Math.random() * FICTIONAL_CAR_BRANDS.length)]} ${FICTIONAL_CAR_MODELS_BY_BRAND[FICTIONAL_CAR_BRANDS[Math.floor(Math.random() * FICTIONAL_CAR_BRANDS.length)]][Math.floor(Math.random() * 4)]}`,
272-
price: (Math.random() * 10000).toFixed(2),
272+
price: Decimal(Math.random() * 10000).toFixed(2),
273273
engine_type: engine_type,
274274
engine_power: engine_type === 'electric' ? null : Math.floor(Math.random() * 400) + 100,
275275
production_year: Math.floor(Math.random() * 31) + 1990,
276276
listed: i % 2 == 0,
277-
mileage: `${Math.floor(Math.random() * 200000)}`,
277+
mileage: Math.floor(Math.random() * 200000),
278278
body_type: BODY_TYPES[Math.floor(Math.random() * BODY_TYPES.length)].value,
279279
});
280280
};

dev-demo/migrations/clickhouse_migrations/1_init.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ CREATE TABLE IF NOT EXISTS cars (
22
id String,
33

44
model String,
5-
price Float64,
5+
price Decimal(18, 2),
66

77
created_at DateTime DEFAULT now(),
88

dev-demo/migrations/prisma/postgres/migrations/20260102130830_test/migration.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
CREATE TABLE "cars" (
33
"id" TEXT NOT NULL,
44
"model" TEXT NOT NULL,
5-
"price" DOUBLE PRECISION NOT NULL,
5+
"price" NUMERIC(18,2) NOT NULL,
66
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
77
"engine_type" TEXT,
88
"engine_power" INTEGER,

dev-demo/migrations/prisma/postgres/schema.postgres.prisma

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ datasource mysql_db {
1010
model cars {
1111
id String @id
1212
model String
13-
price Float
13+
price Decimal @mysql_db.Decimal(18, 2)
1414
created_at DateTime @default(now())
1515
1616
engine_type String?

dev-demo/migrations/prisma/sqlite/migrations/20251224120206_add_cars_model/migration.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
CREATE TABLE "cars" (
33
"id" TEXT NOT NULL PRIMARY KEY,
44
"model" TEXT NOT NULL,
5-
"price" REAL NOT NULL,
5+
"price" DECIMAL(18,2) NOT NULL,
66
"created_at" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
77
"engine_type" TEXT,
88
"engine_power" INTEGER,

0 commit comments

Comments
 (0)