使用Typeform和postgrasql进行DB
我有一个Post实体,它有一个自动生成的createAt列,使用Typeorm中的@CreateDateColumn()。我试图使用Typeorm迁移将5个假帖子条目添加到DB中。npx typeorm migration:create -n FakePosts
问题是,所有5个帖子最终都具有相同的createAt时间戳“2023-05- 30 T02:40:32.318Z”?这是应该的吗我做错了什么?如何配置Typeform以在单个迁移中获得递增的createAt时间戳?
/entity/Post.ts
@ObjectType()
@Entity()
export class Post extends BaseEntity {
@Field()
@PrimaryGeneratedColumn()
id!: number;
@Field()
@CreateDateColumn()
createdAt: Date;
@Field()
@Column()
title!: string;
}
/migration/1685412921219-FakePosts.ts
import { MigrationInterface, QueryRunner } from "typeorm";
export class FakePosts1685414339712 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
insert into post (title, text, "authorId") values ('American Madness', 'In sagittis dui vel nisl. Duis ac nibh. Fusce lacus purus, aliquet at, feugiat non, pretium quis, lectus.
Suspendisse potenti. In eleifend quam a odio. In hac habitasse platea dictumst.
Maecenas ut massa quis augue luctus tincidunt. Nulla mollis molestie lorem. Quisque ut erat.', 1);
insert into post (title, text, "authorId") values ('It''s Pat', 'Etiam vel augue. Vestibulum rutrum rutrum neque. Aenean auctor gravida sem.', 1);
insert into post (title, text, "authorId") values ('Wicked Little Things', 'Pellentesque at nulla. Suspendisse potenti. Cras in purus eu magna vulputate luctus.
Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Vivamus vestibulum sagittis sapien. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.
Etiam vel augue. Vestibulum rutrum rutrum neque. Aenean auctor gravida sem.', 1);
insert into post (title, text, "authorId") values ('There''s Only One Sun', 'Proin interdum mauris non ligula pellentesque ultrices. Phasellus id sapien in sapien iaculis congue. Vivamus metus arcu, adipiscing molestie, hendrerit at, vulputate vitae, nisl.
Aenean lectus. Pellentesque eget nunc. Donec quis orci eget orci vehicula condimentum.', 1);
insert into post (title, text, "authorId") values ('Fairly Odd Movie: Grow Up, Timmy Turner!, A', 'In congue. Etiam justo. Etiam pretium iaculis justo.
In hac habitasse platea dictumst. Etiam faucibus cursus urna. Ut tellus.
Nulla ut erat id mauris vulputate elementum. Nullam varius. Nulla facilisi.', 1);
`);
}
public async down(_: QueryRunner): Promise<void> {}
}
查询所有帖子
{
"data": {
"posts": [
{
"id": 1,
"createdAt": "2023-05-30T02:40:32.318Z",
"title": "American Madness"
},
{
"id": 2,
"createdAt": "2023-05-30T02:40:32.318Z",
"title": "It's Pat"
},
{
"id": 3,
"createdAt": "2023-05-30T02:40:32.318Z",
"title": "Wicked Little Things"
},
{
"id": 4,
"createdAt": "2023-05-30T02:40:32.318Z",
"title": "There's Only One Sun"
},
{
"id": 5,
"createdAt": "2023-05-30T02:40:32.318Z",
"title": "Fairly Odd Movie: Grow Up, Timmy Turner!, A"
}
]
}
}
1条答案
按热度按时间68de4m5k1#
Ben Awad的这段YouTube教程视频解释了这个问题:https://youtu.be/I6ypD7qv3Z8?list=RDCMUC-8QAzbLcRglXeN_MY9blyw&t=27131