Added Drizzle ORM support
This commit is contained in:
156
tests/assets/drizzle/schema-updated.ts
Normal file
156
tests/assets/drizzle/schema-updated.ts
Normal file
@@ -0,0 +1,156 @@
|
||||
// Code generated by relspecgo. DO NOT EDIT.
|
||||
import { pgTable, pgEnum, integer, bigint, smallint, serial, bigserial, smallserial, text, varchar, char, boolean, numeric, real, doublePrecision, timestamp, date, time, interval, json, jsonb, uuid, bytea } from 'drizzle-orm/pg-core';
|
||||
import { sql } from 'drizzle-orm';
|
||||
|
||||
|
||||
// Enums
|
||||
export const userRole = pgEnum('UserRole', ['admin', 'user', 'moderator', 'guest']);
|
||||
export const orderStatus = pgEnum('OrderStatus', ['pending', 'processing', 'shipped', 'delivered', 'cancelled']);
|
||||
|
||||
|
||||
// Table: users
|
||||
export const users = pgTable('users', {
|
||||
id: serial('id').primaryKey(),
|
||||
createdAt: timestamp('created_at').notNull().default(sql`now()`),
|
||||
email: varchar('email').notNull().unique(),
|
||||
isActive: boolean('is_active').notNull().default(true),
|
||||
lastLoginAt: timestamp('last_login_at'),
|
||||
passwordHash: varchar('password_hash').notNull(),
|
||||
profile: jsonb('profile'),
|
||||
role: pgEnum('UserRole')('role').notNull(),
|
||||
updatedAt: timestamp('updated_at').notNull().default(sql`now()`),
|
||||
username: varchar('username').notNull().unique(),
|
||||
});
|
||||
|
||||
// Types for users
|
||||
export type Users = typeof users.$inferSelect;
|
||||
export type NewUsers = typeof users.$inferInsert;
|
||||
// Table: profiles
|
||||
export const profiles = pgTable('profiles', {
|
||||
id: serial('id').primaryKey(),
|
||||
avatarUrl: varchar('avatar_url'),
|
||||
bio: text('bio'),
|
||||
createdAt: timestamp('created_at').notNull().default(sql`now()`),
|
||||
dateOfBirth: date('date_of_birth'),
|
||||
firstName: varchar('first_name'),
|
||||
lastName: varchar('last_name'),
|
||||
phoneNumber: varchar('phone_number'),
|
||||
updatedAt: timestamp('updated_at').notNull().default(sql`now()`),
|
||||
userId: integer('user_id').notNull().unique().references(() => users.id),
|
||||
});
|
||||
|
||||
// Types for profiles
|
||||
export type Profiles = typeof profiles.$inferSelect;
|
||||
export type NewProfiles = typeof profiles.$inferInsert;
|
||||
// Table: posts
|
||||
export const posts = pgTable('posts', {
|
||||
id: serial('id').primaryKey(),
|
||||
authorId: integer('author_id').notNull().references(() => users.id),
|
||||
content: text('content').notNull(),
|
||||
createdAt: timestamp('created_at').notNull().default(sql`now()`),
|
||||
excerpt: text('excerpt'),
|
||||
featuredImage: varchar('featured_image'),
|
||||
isPublished: boolean('is_published').notNull().default(false),
|
||||
publishedAt: timestamp('published_at'),
|
||||
slug: varchar('slug').notNull().unique(),
|
||||
title: varchar('title').notNull(),
|
||||
updatedAt: timestamp('updated_at').notNull().default(sql`now()`),
|
||||
viewCount: integer('view_count').notNull().default(0),
|
||||
});
|
||||
|
||||
// Types for posts
|
||||
export type Posts = typeof posts.$inferSelect;
|
||||
export type NewPosts = typeof posts.$inferInsert;
|
||||
// Table: comments
|
||||
export const comments = pgTable('comments', {
|
||||
id: serial('id').primaryKey(),
|
||||
authorId: integer('author_id').notNull().references(() => users.id),
|
||||
content: text('content').notNull(),
|
||||
createdAt: timestamp('created_at').notNull().default(sql`now()`),
|
||||
isApproved: boolean('is_approved').notNull().default(false),
|
||||
parentId: integer('parent_id').references(() => comments.id),
|
||||
postId: integer('post_id').notNull().references(() => posts.id),
|
||||
updatedAt: timestamp('updated_at').notNull().default(sql`now()`),
|
||||
});
|
||||
|
||||
// Types for comments
|
||||
export type Comments = typeof comments.$inferSelect;
|
||||
export type NewComments = typeof comments.$inferInsert;
|
||||
// Table: categories
|
||||
export const categories = pgTable('categories', {
|
||||
id: serial('id').primaryKey(),
|
||||
createdAt: timestamp('created_at').notNull().default(sql`now()`),
|
||||
description: text('description'),
|
||||
name: varchar('name').notNull().unique(),
|
||||
parentId: integer('parent_id').references(() => categories.id),
|
||||
slug: varchar('slug').notNull().unique(),
|
||||
updatedAt: timestamp('updated_at').notNull().default(sql`now()`),
|
||||
});
|
||||
|
||||
// Types for categories
|
||||
export type Categories = typeof categories.$inferSelect;
|
||||
export type NewCategories = typeof categories.$inferInsert;
|
||||
// Table: post_categories
|
||||
export const postCategories = pgTable('post_categories', {
|
||||
categoryId: integer('category_id').notNull().references(() => categories.id),
|
||||
createdAt: timestamp('created_at').notNull().default(sql`now()`),
|
||||
postId: integer('post_id').notNull().references(() => posts.id),
|
||||
});
|
||||
|
||||
// Types for post_categories
|
||||
export type PostCategories = typeof postCategories.$inferSelect;
|
||||
export type NewPostCategories = typeof postCategories.$inferInsert;
|
||||
// Table: tags
|
||||
export const tags = pgTable('tags', {
|
||||
id: serial('id').primaryKey(),
|
||||
createdAt: timestamp('created_at').notNull().default(sql`now()`),
|
||||
name: varchar('name').notNull().unique(),
|
||||
slug: varchar('slug').notNull().unique(),
|
||||
});
|
||||
|
||||
// Types for tags
|
||||
export type Tags = typeof tags.$inferSelect;
|
||||
export type NewTags = typeof tags.$inferInsert;
|
||||
// Table: post_tags
|
||||
export const postTags = pgTable('post_tags', {
|
||||
createdAt: timestamp('created_at').notNull().default(sql`now()`),
|
||||
postId: integer('post_id').notNull().references(() => posts.id),
|
||||
tagId: integer('tag_id').notNull().references(() => tags.id),
|
||||
});
|
||||
|
||||
// Types for post_tags
|
||||
export type PostTags = typeof postTags.$inferSelect;
|
||||
export type NewPostTags = typeof postTags.$inferInsert;
|
||||
// Table: orders
|
||||
export const orders = pgTable('orders', {
|
||||
id: serial('id').primaryKey(),
|
||||
billingAddress: jsonb('billing_address').notNull(),
|
||||
completedAt: timestamp('completed_at'),
|
||||
createdAt: timestamp('created_at').notNull().default(sql`now()`),
|
||||
currency: varchar('currency').notNull().default('USD'),
|
||||
notes: text('notes'),
|
||||
orderNumber: varchar('order_number').notNull().unique(),
|
||||
shippingAddress: jsonb('shipping_address').notNull(),
|
||||
status: pgEnum('OrderStatus')('status').notNull().default('pending'),
|
||||
totalAmount: numeric('total_amount').notNull(),
|
||||
updatedAt: timestamp('updated_at').notNull().default(sql`now()`),
|
||||
userId: integer('user_id').notNull().references(() => users.id),
|
||||
});
|
||||
|
||||
// Types for orders
|
||||
export type Orders = typeof orders.$inferSelect;
|
||||
export type NewOrders = typeof orders.$inferInsert;
|
||||
// Table: sessions
|
||||
export const sessions = pgTable('sessions', {
|
||||
id: uuid('id').primaryKey().default(sql`gen_random_uuid()`),
|
||||
createdAt: timestamp('created_at').notNull().default(sql`now()`),
|
||||
expiresAt: timestamp('expires_at').notNull(),
|
||||
ipAddress: varchar('ip_address'),
|
||||
token: varchar('token').notNull().unique(),
|
||||
userAgent: text('user_agent'),
|
||||
userId: integer('user_id').notNull().references(() => users.id),
|
||||
});
|
||||
|
||||
// Types for sessions
|
||||
export type Sessions = typeof sessions.$inferSelect;
|
||||
export type NewSessions = typeof sessions.$inferInsert;
|
||||
90
tests/assets/drizzle/schema.ts
Normal file
90
tests/assets/drizzle/schema.ts
Normal file
@@ -0,0 +1,90 @@
|
||||
// Code generated by relspecgo. DO NOT EDIT.
|
||||
import { pgTable, pgEnum, integer, bigint, smallint, serial, bigserial, smallserial, text, varchar, char, boolean, numeric, real, doublePrecision, timestamp, date, time, interval, json, jsonb, uuid, bytea } from 'drizzle-orm/pg-core';
|
||||
import { sql } from 'drizzle-orm';
|
||||
|
||||
|
||||
// Enums
|
||||
export const role = pgEnum('Role', ['USER', 'ADMIN']);
|
||||
export type Role = 'USER' | 'ADMIN';
|
||||
|
||||
|
||||
// Table: User
|
||||
export interface User {
|
||||
id: number;
|
||||
email: string;
|
||||
name: string | null;
|
||||
profile: string | null;
|
||||
role: Role;
|
||||
}
|
||||
|
||||
export const user = pgTable('User', {
|
||||
id: integer('id').primaryKey().generatedAlwaysAsIdentity(),
|
||||
email: text('email').notNull().unique(),
|
||||
name: text('name'),
|
||||
profile: text('profile'),
|
||||
role: pgEnum('Role')('role').notNull().default('USER'),
|
||||
});
|
||||
|
||||
export type NewUser = typeof user.$inferInsert;
|
||||
// Table: Profile
|
||||
export interface Profile {
|
||||
id: number;
|
||||
bio: string;
|
||||
user: string;
|
||||
userId: number;
|
||||
}
|
||||
|
||||
export const profile = pgTable('Profile', {
|
||||
id: integer('id').primaryKey().generatedAlwaysAsIdentity(),
|
||||
bio: text('bio').notNull(),
|
||||
user: text('user').notNull(),
|
||||
userId: integer('userId').notNull().unique().references(() => user.id),
|
||||
});
|
||||
|
||||
export type NewProfile = typeof profile.$inferInsert;
|
||||
// Table: Post
|
||||
export interface Post {
|
||||
id: number;
|
||||
author: string;
|
||||
authorId: number;
|
||||
createdAt: Date;
|
||||
published: boolean;
|
||||
title: string;
|
||||
updatedAt: Date; // @updatedAt
|
||||
}
|
||||
|
||||
export const post = pgTable('Post', {
|
||||
id: integer('id').primaryKey().generatedAlwaysAsIdentity(),
|
||||
author: text('author').notNull(),
|
||||
authorId: integer('authorId').notNull().references(() => user.id),
|
||||
createdAt: timestamp('createdAt').notNull().default(sql`now()`),
|
||||
published: boolean('published').notNull().default(false),
|
||||
title: text('title').notNull(),
|
||||
updatedAt: timestamp('updatedAt').notNull(), // @updatedAt
|
||||
});
|
||||
|
||||
export type NewPost = typeof post.$inferInsert;
|
||||
// Table: Category
|
||||
export interface Category {
|
||||
id: number;
|
||||
name: string;
|
||||
}
|
||||
|
||||
export const category = pgTable('Category', {
|
||||
id: integer('id').primaryKey().generatedAlwaysAsIdentity(),
|
||||
name: text('name').notNull(),
|
||||
});
|
||||
|
||||
export type NewCategory = typeof category.$inferInsert;
|
||||
// Table: _CategoryToPost
|
||||
export interface Categorytopost {
|
||||
categoryId: number;
|
||||
postId: number;
|
||||
}
|
||||
|
||||
export const Categorytopost = pgTable('_CategoryToPost', {
|
||||
categoryId: integer('CategoryId').primaryKey().references(() => category.id),
|
||||
postId: integer('PostId').primaryKey().references(() => post.id),
|
||||
});
|
||||
|
||||
export type NewCategorytopost = typeof Categorytopost.$inferInsert;
|
||||
Reference in New Issue
Block a user