import { Entity, Column, PrimaryGeneratedColumn, CreateDateColumn, UpdateDateColumn, Index, ManyToOne, JoinColumn, } from 'typeorm'; import { User } from './user.entity'; import { OAuthProvider } from './oauth-provider.enum'; @Entity({ schema: 'auth', name: 'oauth_connections' }) @Index(['tenant_id', 'user_id']) @Index(['tenant_id', 'provider', 'provider_user_id'], { unique: true }) export class OAuthConnection { @PrimaryGeneratedColumn('uuid') id: string; @Column({ type: 'uuid' }) @Index() tenant_id: string; @Column({ type: 'uuid' }) @Index() user_id: string; @Column({ type: 'enum', enum: OAuthProvider, enumName: 'auth.oauth_provider', }) provider: OAuthProvider; @Column({ type: 'varchar', length: 255 }) provider_user_id: string; @Column({ type: 'varchar', length: 255, nullable: true }) provider_email: string | null; @Column({ type: 'varchar', length: 255, nullable: true }) provider_name: string | null; @Column({ type: 'varchar', length: 500, nullable: true }) provider_avatar_url: string | null; @Column({ type: 'text', nullable: true }) access_token: string | null; @Column({ type: 'text', nullable: true }) refresh_token: string | null; @Column({ type: 'timestamp with time zone', nullable: true }) token_expires_at: Date | null; @Column({ type: 'jsonb', nullable: true }) scopes: string[] | null; @Column({ type: 'jsonb', nullable: true }) raw_data: Record | null; @CreateDateColumn({ type: 'timestamp with time zone' }) created_at: Date; @UpdateDateColumn({ type: 'timestamp with time zone' }) updated_at: Date; @Column({ type: 'timestamp with time zone', nullable: true }) last_used_at: Date | null; // Relations @ManyToOne(() => User, { onDelete: 'CASCADE' }) @JoinColumn({ name: 'user_id' }) user: User; }