add index

This commit is contained in:
2025-12-11 18:37:50 +03:30
parent a54e8eb9f3
commit 49ec05b410
12 changed files with 42 additions and 11 deletions
@@ -1,4 +1,4 @@
import { Entity, ManyToOne, Unique } from '@mikro-orm/core';
import { Entity, Index, ManyToOne, Unique } from '@mikro-orm/core';
import { BaseEntity } from '../../../common/entities/base.entity';
import { Role } from '../../roles/entities/role.entity';
import { Restaurant } from 'src/modules/restaurants/entities/restaurant.entity';
@@ -6,6 +6,9 @@ import { Admin } from './admin.entity';
@Entity({ tableName: 'admin_roles' })
@Unique({ properties: ['admin', 'restaurant'] })
@Index({ properties: ['admin', 'restaurant'] })
@Index({ properties: ['admin'] })
@Index({ properties: ['restaurant'] })
export class AdminRole extends BaseEntity {
@ManyToOne(() => Admin)
admin!: Admin;
@@ -1,4 +1,4 @@
import { Entity, Enum, Property } from '@mikro-orm/core';
import { Entity, Enum, Index, Property } from '@mikro-orm/core';
import { BaseEntity } from '../../../common/entities/base.entity';
@@ -8,6 +8,9 @@ export enum RefreshTokenType {
}
@Entity({ tableName: 'refreshtokens' })
@Index({ properties: ['ownerId', 'restId', 'type'] })
@Index({ properties: ['hashedToken'] })
@Index({ properties: ['expiresAt'] })
export class RefreshToken extends BaseEntity {
@Property({ type: 'varchar', length: 255 })
hashedToken!: string;
@@ -1,4 +1,4 @@
import { Entity, ManyToOne, Property, Enum, Unique } from '@mikro-orm/core';
import { Entity, Index, ManyToOne, Property, Enum, Unique } from '@mikro-orm/core';
import { BaseEntity } from '../../../common/entities/base.entity';
import { Restaurant } from '../../restaurants/entities/restaurant.entity';
import { normalizePhone } from '../../utils/phone.util';
@@ -6,6 +6,9 @@ import { CouponType } from '../interface/coupon';
@Entity({ tableName: 'coupons' })
@Unique({ properties: ['code', 'restaurant'] })
@Index({ properties: ['restaurant', 'code', 'isActive'] })
@Index({ properties: ['restaurant', 'isActive'] })
@Index({ properties: ['code'] })
export class Coupon extends BaseEntity {
@ManyToOne(() => Restaurant)
restaurant!: Restaurant;
@@ -1,9 +1,11 @@
import { Entity, Property, Collection, OneToMany, ManyToOne } from '@mikro-orm/core';
import { Entity, Index, Property, Collection, OneToMany, ManyToOne } from '@mikro-orm/core';
import { Food } from './food.entity';
import { BaseEntity } from '../../../common/entities/base.entity';
import { Restaurant } from 'src/modules/restaurants/entities/restaurant.entity';
@Entity({ tableName: 'categories' })
@Index({ properties: ['restaurant', 'isActive'] })
@Index({ properties: ['isActive'] })
export class Category extends BaseEntity {
@Property()
title!: string;
+4 -1
View File
@@ -1,10 +1,13 @@
import { Cascade, Collection, Entity, ManyToOne, OneToMany, Property } from '@mikro-orm/core';
import { Cascade, Collection, Entity, Index, ManyToOne, OneToMany, Property } from '@mikro-orm/core';
import { Category } from './category.entity';
import { BaseEntity } from '../../../common/entities/base.entity';
import { Restaurant } from '../../../modules/restaurants/entities/restaurant.entity';
import { Review } from 'src/modules/review/entities/review.entity';
@Entity({ tableName: 'foods' })
@Index({ properties: ['restaurant', 'isActive'] })
@Index({ properties: ['category', 'isActive'] })
@Index({ properties: ['isActive'] })
export class Food extends BaseEntity {
@ManyToOne(() => Restaurant)
restaurant: Restaurant;
@@ -1,9 +1,11 @@
import { Entity, ManyToOne, Property } from '@mikro-orm/core';
import { Entity, Index, ManyToOne, Property } from '@mikro-orm/core';
import { BaseEntity } from '../../../common/entities/base.entity';
import { Order } from './order.entity';
import { Food } from '../../foods/entities/food.entity';
@Entity({ tableName: 'order_items' })
@Index({ properties: ['order'] })
@Index({ properties: ['food'] })
export class OrderItem extends BaseEntity {
@ManyToOne(() => Order)
order!: Order;
@@ -1,5 +1,6 @@
import {
Entity,
Index,
ManyToOne,
OneToMany,
Property,
@@ -22,6 +23,11 @@ import { Delivery } from '../../delivery/entities/delivery.entity';
@Entity({ tableName: 'orders' })
@Unique({ properties: ['restaurant', 'orderNumber'] })
@Index({ properties: ['restaurant', 'status'] })
@Index({ properties: ['user', 'status'] })
@Index({ properties: ['restaurant', 'orderNumber'] })
@Index({ properties: ['status'] })
@Index({ properties: ['paymentStatus'] })
export class Order extends BaseEntity {
@ManyToOne(() => User)
user!: User;
@@ -1,8 +1,10 @@
import { Collection, Entity, OneToMany, Property } from '@mikro-orm/core';
import { Collection, Entity, Index, OneToMany, Property } from '@mikro-orm/core';
import { BaseEntity } from '../../../common/entities/base.entity';
import { Delivery } from '../../delivery/entities/delivery.entity';
@Entity({ tableName: 'restaurants' })
@Index({ properties: ['isActive'] })
@Index({ properties: ['slug', 'isActive'] })
export class Restaurant extends BaseEntity {
// --- اطلاعات پایه ---
@Property()
+4 -1
View File
@@ -1,4 +1,4 @@
import { Entity, ManyToOne, Property, Unique, Enum } from '@mikro-orm/core';
import { Entity, Index, ManyToOne, Property, Unique, Enum } from '@mikro-orm/core';
import { BaseEntity } from '../../../common/entities/base.entity';
import { Food } from '../../foods/entities/food.entity';
import { User } from '../../users/entities/user.entity';
@@ -8,6 +8,9 @@ import { ReviewStatus } from '../enums/review-status.enum';
@Entity({ tableName: 'reviews' })
@Unique({ properties: ['order', 'food', 'user'] })
@Index({ properties: ['food', 'status'] })
@Index({ properties: ['user'] })
@Index({ properties: ['order'] })
export class Review extends BaseEntity {
@ManyToOne(() => Order)
order: Order;
+2 -1
View File
@@ -1,4 +1,4 @@
import { Collection, Entity, ManyToMany, OneToMany, ManyToOne, Property } from '@mikro-orm/core';
import { Collection, Entity, Index, ManyToMany, OneToMany, ManyToOne, Property } from '@mikro-orm/core';
import { BaseEntity } from '../../../common/entities/base.entity';
import { Permission } from './permission.entity';
import { Restaurant } from '../../restaurants/entities/restaurant.entity';
@@ -6,6 +6,7 @@ import { RolePermission } from './rolePermission.entity';
import { AdminRole } from 'src/modules/admin/entities/adminRole.entity';
@Entity({ tableName: 'roles' })
@Index({ properties: ['restaurant'] })
export class Role extends BaseEntity {
@Property()
name!: string;
+2 -1
View File
@@ -1,10 +1,11 @@
import { Entity, Property, OneToMany, Collection, Cascade } from '@mikro-orm/core';
import { Entity, Index, Property, OneToMany, Collection, Cascade } from '@mikro-orm/core';
import { BaseEntity } from '../../../common/entities/base.entity';
import { UserAddress } from './user-address.entity';
import { Order } from 'src/modules/orders/entities/order.entity';
import { normalizePhone } from '../../utils/phone.util';
@Entity({ tableName: 'users' })
@Index({ properties: ['isActive'] })
export class User extends BaseEntity {
@OneToMany(() => Order, order => order.user)
orders = new Collection<Order>(this);