Skip to content

Commit

Permalink
Removing useless table
Browse files Browse the repository at this point in the history
  • Loading branch information
davidleonm committed Jan 20, 2025
1 parent fc5d1b5 commit e291c61
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 214 deletions.
10 changes: 5 additions & 5 deletions db/db.seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,23 @@ async function main(): Promise<void> {
}

async function setUsers(tx: Prisma.TransactionClient): Promise<void> {
const passwordHashed: string = await bcrypt.hash('123456', GlobalConfig.auth.hashSaltRounds)
const passwordHashed: string = await bcrypt.hash(GlobalConfig.database.password, GlobalConfig.auth.hashSaltRounds)

await tx.user.create({ data: { login: 'dashboard', password: passwordHashed, role: Role.Read } })
await tx.user.create({ data: { login: 'sensors', password: passwordHashed, role: Role.Write } })
}

async function setMeasurements(tx: Prisma.TransactionClient): Promise<void> {
const oneYearAgo = new Date()
oneYearAgo.setFullYear(oneYearAgo.getFullYear() - 1)
const oneMonthAgo = new Date()
oneMonthAgo.setMonth(oneMonthAgo.getMonth() - 1)

const intervals: Date[] = getDateIntervals(oneYearAgo, new Date(), 5)
const intervals: Date[] = getDateIntervals(oneMonthAgo, new Date(), 5)
for (const interval of intervals) {
await tx.ambientTemperature.create({ data: { dateTime: interval, temperature: getRandomBetween(-5, 40) } })
await tx.groundTemperature.create({ data: { dateTime: interval, temperature: getRandomBetween(-5, 40) } })
await tx.airMeasurement.create({
data: {
dateTime: interval,
temperature: getRandomBetween(-5, 40),
humidity: getRandomBetween(10, 100),
pressure: getRandomBetween(900, 1100),
},
Expand Down
20 changes: 6 additions & 14 deletions db/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ datasource db {
url = env("DATABASE_CONNECTION_STRING")
}

model AmbientTemperature {
id BigInt @id(map: "ambient_temperatures_pkey") @default(autoincrement())
model AirMeasurement {
id BigInt @id(map: "air_measurements_pkey") @default(autoincrement())
temperature Int @map("temperature") @db.SmallInt
humidity Int @map("humidity") @db.SmallInt
pressure Int @map("pressure") @db.SmallInt
dateTime DateTime @map("date_time") @db.Timestamptz(0)
@@index([dateTime], map: "ambient_temperatures_date_time_idx")
@@map("ambient_temperatures")
@@index([dateTime], map: "air_measurements_date_time_idx")
@@map("air_measurements")
}

model GroundTemperature {
Expand All @@ -28,16 +30,6 @@ model GroundTemperature {
@@map("ground_temperatures")
}

model AirMeasurement {
id BigInt @id(map: "air_measurements_pkey") @default(autoincrement())
humidity Int @map("humidity") @db.SmallInt
pressure Int @map("pressure") @db.SmallInt
dateTime DateTime @map("date_time") @db.Timestamptz(0)
@@index([dateTime], map: "air_measurements_date_time_idx")
@@map("air_measurements")
}

model WindMeasurement {
id BigInt @id(map: "wind_measurements_pkey") @default(autoincrement())
speed Int @map("speed") @db.SmallInt
Expand Down
Loading

0 comments on commit e291c61

Please sign in to comment.