initial commit
This commit is contained in:
59
schema/entity/AccountEntity.ts
Normal file
59
schema/entity/AccountEntity.ts
Normal file
@ -0,0 +1,59 @@
|
||||
import { Column, Entity, ManyToOne, PrimaryGeneratedColumn, type Relation } from "typeorm"
|
||||
import { UserEntity } from "./UserEntity"
|
||||
import { transformer } from "../utils/transformers"
|
||||
// import UserEntity from "./UserEntity"
|
||||
// import { transformer } from "../utils/transformers"
|
||||
|
||||
@Entity({ name: "accounts" })
|
||||
export default class AccountEntity {
|
||||
@PrimaryGeneratedColumn("uuid")
|
||||
id!: string
|
||||
|
||||
@Column({ type: "uuid" })
|
||||
userId!: string
|
||||
|
||||
@Column()
|
||||
type!: string
|
||||
|
||||
@Column()
|
||||
provider!: string
|
||||
|
||||
@Column()
|
||||
providerAccountId!: string
|
||||
|
||||
@Column({ type: "varchar", nullable: true })
|
||||
refresh_token!: string | null
|
||||
|
||||
@Column({ type: "varchar", nullable: true })
|
||||
access_token!: string | null
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
type: "bigint",
|
||||
transformer: transformer.bigint,
|
||||
})
|
||||
expires_at!: number | null
|
||||
|
||||
@Column({ type: "varchar", nullable: true })
|
||||
token_type!: string | null
|
||||
|
||||
@Column({ type: "varchar", nullable: true })
|
||||
scope!: string | null
|
||||
|
||||
@Column({ type: "varchar", nullable: true })
|
||||
id_token!: string | null
|
||||
|
||||
@Column({ type: "varchar", nullable: true })
|
||||
session_state!: string | null
|
||||
|
||||
@Column({ type: "varchar", nullable: true })
|
||||
oauth_token_secret!: string | null
|
||||
|
||||
@Column({ type: "varchar", nullable: true })
|
||||
oauth_token!: string | null
|
||||
|
||||
@ManyToOne(() => UserEntity, (user) => user.accounts, {
|
||||
createForeignKeyConstraints: true,
|
||||
})
|
||||
user!: Relation<UserEntity>
|
||||
}
|
||||
22
schema/entity/SessionEntity.ts
Normal file
22
schema/entity/SessionEntity.ts
Normal file
@ -0,0 +1,22 @@
|
||||
import { Column, Entity, ManyToOne, PrimaryGeneratedColumn, type Relation } from "typeorm"
|
||||
import { UserEntity } from "./UserEntity"
|
||||
import { transformer } from "../utils/transformers"
|
||||
|
||||
|
||||
@Entity({ name: "sessions" })
|
||||
export default class SessionEntity {
|
||||
@PrimaryGeneratedColumn("uuid")
|
||||
id!: string
|
||||
|
||||
@Column({ unique: true })
|
||||
sessionToken!: string
|
||||
|
||||
@Column({ type: "uuid" })
|
||||
userId!: string
|
||||
|
||||
@Column({ transformer: transformer.date })
|
||||
expires!: string
|
||||
|
||||
@ManyToOne(() => UserEntity, (user) => user.sessions)
|
||||
user!: Relation<UserEntity>
|
||||
}
|
||||
9
schema/entity/TestMigrationEntity.ts
Normal file
9
schema/entity/TestMigrationEntity.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import { Column, Entity } from "typeorm"
|
||||
import { UserEntity } from "./UserEntity"
|
||||
import AbstractBaseEntity from "./abstract/AbstractBaseEntity"
|
||||
|
||||
@Entity({ name: "haha" })
|
||||
export default class TestMigrationEntity extends AbstractBaseEntity{
|
||||
@Column()
|
||||
provider!: string
|
||||
}
|
||||
33
schema/entity/UserEntity.ts
Normal file
33
schema/entity/UserEntity.ts
Normal file
@ -0,0 +1,33 @@
|
||||
import { Column, Entity, OneToMany, PrimaryGeneratedColumn, type Relation } from "typeorm"
|
||||
import SessionEntity from "./SessionEntity"
|
||||
import AccountEntity from "./AccountEntity"
|
||||
import { transformer } from "../utils/transformers"
|
||||
import AbstractBaseEntity from "./abstract/AbstractBaseEntity"
|
||||
|
||||
@Entity({ name: "users" })
|
||||
export class UserEntity extends AbstractBaseEntity {
|
||||
|
||||
@Column({ type: "varchar", nullable: true })
|
||||
name!: string | null
|
||||
|
||||
// @Column({ type: "varchar", nullable: true })
|
||||
// password!: string | null
|
||||
|
||||
@Column({ type: "varchar", nullable: true, unique: true })
|
||||
email!: string | null
|
||||
|
||||
// @Column({ type: "varchar", nullable: true, transformer: transformer.date })
|
||||
// emailVerified!: string | null
|
||||
|
||||
@Column({ type: "varchar", nullable: true })
|
||||
image!: string | null
|
||||
|
||||
// @Column({ type: "varchar", nullable: true })
|
||||
// role!: string | null
|
||||
|
||||
@OneToMany(() => SessionEntity, (session) => session.userId)
|
||||
sessions!: Relation<SessionEntity>[]
|
||||
|
||||
@OneToMany(() => AccountEntity, (account) => account.userId)
|
||||
accounts!: Relation<AccountEntity>[]
|
||||
}
|
||||
17
schema/entity/VerificationTokenEntity.ts
Normal file
17
schema/entity/VerificationTokenEntity.ts
Normal file
@ -0,0 +1,17 @@
|
||||
import { Column, Entity, PrimaryGeneratedColumn } from "typeorm"
|
||||
import { transformer } from "../utils/transformers"
|
||||
|
||||
@Entity({ name: "verification_tokens" })
|
||||
export default class VerificationTokenEntity {
|
||||
@PrimaryGeneratedColumn("uuid")
|
||||
id!: string
|
||||
|
||||
@Column()
|
||||
token!: string
|
||||
|
||||
@Column()
|
||||
identifier!: string
|
||||
|
||||
@Column({ transformer: transformer.date })
|
||||
expires!: string
|
||||
}
|
||||
6
schema/entity/abstract/AbstractBaseEntity.ts
Normal file
6
schema/entity/abstract/AbstractBaseEntity.ts
Normal file
@ -0,0 +1,6 @@
|
||||
import { PrimaryGeneratedColumn } from "typeorm";
|
||||
|
||||
export default abstract class AbstractBaseEntity {
|
||||
@PrimaryGeneratedColumn("uuid")
|
||||
id!: string
|
||||
}
|
||||
Reference in New Issue
Block a user