Skip to content

Commit

Permalink
docs(backend): Add indexes into i18n column
Browse files Browse the repository at this point in the history
  • Loading branch information
aXenDeveloper committed Feb 29, 2024
1 parent 083f716 commit 1e6a0e5
Showing 1 changed file with 27 additions and 15 deletions.
42 changes: 27 additions & 15 deletions docs/pages/backend/i18n.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,35 @@ The translation table must have:
- any fields for relation with main table (in our case `nav_id`)

```ts
export const core_nav_name = pgTable("core_nav_name", {
id: serial("id").primaryKey(),
nav_id: serial("nav_id")
.notNull()
.references(() => core_nav.id, {
onDelete: "cascade"
}),
language_code: varchar("language_code")
.notNull()
.references(() => core_languages.code, {
onDelete: "cascade"
}),
value: varchar("value", { length: 50 }).notNull()
});
import { relations } from "drizzle-orm";
import { index, pgTable, serial, varchar } from "drizzle-orm/pg-core";

export const core_nav_name = pgTable(
"core_nav_name",
{
id: serial("id").primaryKey(),
nav_id: serial("nav_id")
.notNull()
.references(() => core_nav.id, {
onDelete: "cascade"
}),
language_code: varchar("language_code")
.notNull()
.references(() => core_languages.code, {
onDelete: "cascade"
}),
value: varchar("value", { length: 50 }).notNull()
},
table => ({
nav_id_idx: index("core_nav_name_nav_id_idx").on(table.nav_id),
language_code_idx: index("core_nav_name_language_code_idx").on(
table.language_code
)
})
);
```

Remember to set `onDelete: 'cascade'` action into references. We want to delete translation when we delete main table.
Remember to set `onDelete: 'cascade'` action into references and set `indexes` for best performerce. We want to delete translation when we delete main table.

### Relation

Expand Down

0 comments on commit 1e6a0e5

Please sign in to comment.