Skip to content

Commit

Permalink
Fix: createdAt & updatedAt fields timestamps inconsistency (#502)
Browse files Browse the repository at this point in the history
* changed AbstractWarthogModel's createdAt & updatedAt field types

* fix: don't update createAt field everytime entity is saved

* set entity's updatedAt field to blocktime whenever entity is saved

affects: @joystream/hydra-cli, @joystream/hydra-indexer-gateway
  • Loading branch information
zeeshanakram3 authored Jul 20, 2022
1 parent dbed2ec commit cbae090
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 23 deletions.
4 changes: 2 additions & 2 deletions packages/hydra-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"@inquirer/input": "^0.0.13-alpha.0",
"@inquirer/password": "^0.0.12-alpha.0",
"@inquirer/select": "^0.0.13-alpha.0",
"@joystream/warthog": "^2.41.8",
"@joystream/warthog": "^2.41.9",
"@oclif/command": "^1.5.20",
"@oclif/config": "^1",
"@oclif/errors": "^1.3.3",
Expand Down Expand Up @@ -80,7 +80,7 @@
"lodash": "^4.17.20",
"pg": "^8.3.2",
"pg-listen": "^1.7.0",
"@joystream/warthog": "^2.41.8"
"@joystream/warthog": "^2.41.9"
},
"devDependencies": {
"@oclif/dev-cli": "^1",
Expand Down
2 changes: 1 addition & 1 deletion packages/hydra-indexer-gateway/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"@joystream/bn-typeorm": "^4.0.0-alpha.3",
"@joystream/hydra-common": "^4.0.0-alpha.3",
"@joystream/hydra-db-utils": "^4.0.0-alpha.3",
"@joystream/warthog": "^2.41.8",
"@joystream/warthog": "^2.41.9",
"@types/ioredis": "^4.17.4",
"bn.js": "^5.2.1",
"dotenv": "^8.2.0",
Expand Down
11 changes: 3 additions & 8 deletions packages/hydra-indexer/src/entities/AbstractWarthogModel.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
import {
Column,
CreateDateColumn,
UpdateDateColumn,
VersionColumn,
} from 'typeorm'
import { Column, VersionColumn } from 'typeorm'

/**
* Abstract class with Warthog fields. All Entities exposed as warthog model class
* should extend it.
*/
export abstract class AbstractWarthogModel {
// Warthog Fields
@CreateDateColumn()
@Column()
createdAt!: Date

@Column({
default: 'hydra-indexer',
})
createdById!: string

@UpdateDateColumn({ nullable: true })
@Column({ nullable: true })
updatedAt?: Date

@Column({
Expand Down
12 changes: 4 additions & 8 deletions packages/hydra-processor/src/executor/TransactionalExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,19 +175,15 @@ async function fillRequiredWarthogFields<T extends Record<string, unknown>>(

// set createdAt to the block timestamp if not set
// eslint-disable-next-line no-prototype-builtins
if (entity.hasOwnProperty('createdAt') || entity.createdAt === undefined) {
if (!entity.hasOwnProperty('createdAt') || entity.createdAt === undefined) {
Object.assign(entity, {
createdAt: new Date(block.timestamp),
})
}

// set updatedAt to the block timestamp if not set
// eslint-disable-next-line no-prototype-builtins
if (!entity.hasOwnProperty('updatedAt') || entity.updatedAt === undefined) {
Object.assign(entity, {
updatedAt: new Date(block.timestamp),
})
}
Object.assign(entity, {
updatedAt: new Date(block.timestamp),
})

return entity
}
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1171,10 +1171,10 @@
resolved "https://registry.yarnpkg.com/@joystream/prettier-config/-/prettier-config-1.0.0.tgz#d87c6370244f39281d9052c619977ca60f6e21cd"
integrity sha512-ZY2H1PH05Yhn22B7G8ilLyIT9LxQ9b/PyErkPx8OOW+znary5QgExMhgBl1Gmv3k9m/QX1qIxKHZveO4R2yfeA==

"@joystream/warthog@^2.41.8":
version "2.41.8"
resolved "https://registry.yarnpkg.com/@joystream/warthog/-/warthog-2.41.8.tgz#c5a837ab59306c18da22bccede8bbbc8dd0e5a83"
integrity sha512-IWlEf0RZf8gvMZ+u6Rkwsq5q4CFrrSl1LOrSpdK38AprYqKQtiMcQ/OTFE+gSB+2bDz42RqHkc+a3U1/3a7Ehw==
"@joystream/warthog@^2.41.9":
version "2.41.9"
resolved "https://registry.yarnpkg.com/@joystream/warthog/-/warthog-2.41.9.tgz#7cfb16df80cb43339e541026af09ff38909eae82"
integrity sha512-4RUZYueSyv3KILsNeUAtCNPpNm0odp0aLSdRHt3E/DvFTQRyjPEwM7CvvqpLAKHdJY1AP8ntLQCUxWXL888ioA==
dependencies:
"@apollographql/graphql-playground-react" "/~https://github.com/Joystream/graphql-playground/releases/download/graphql-playground-react%401.7.30/graphql-playground-react-v1.7.30.tgz"
"@types/app-root-path" "^1.2.4"
Expand Down

0 comments on commit cbae090

Please sign in to comment.