GUIDAO2
GUIDAO2
DTDrizzle Team
Created by GUIDAO2 on 1/18/2024 in #help
Multi-tenancy
or return it as an array, but it doesnt seem like drizzle can understand it.
3 replies
DTDrizzle Team
Created by GUIDAO2 on 1/18/2024 in #help
Multi-tenancy
I think that it could be eazy to solve if we could just do
import { ColumnBuilderBaseConfig, ColumnDataType } from "drizzle-orm";
import { PgColumnBuilderBase, pgSchema, pgTable, serial, text, varchar } from "drizzle-orm/pg-core";

export const configSchema = pgSchema("config");
export const UserConfig = configSchema.table("user_config", {
id: serial("id").primaryKey(),

email: varchar("email", { length: 255 }).notNull().unique(),
password: varchar("password", { length: 255 }),

schema: text("schema"),
});

export function getNewSchema(schema: string) {
const modelSchema = pgSchema(schema);

const Users = modelSchema.table("user", {
id: serial("id").primaryKey(),

name: text("name"),
});

const Contracts = modelSchema.table("contract", {
id: serial("id").primaryKey(),
});

const exampleTable = modelSchema.table("example_table", {
id: serial("id").primaryKey(),
});

return { Users, Contracts, exampleTable };
// ^^^^^^^^^^ this.
}

export const schema1 = getNewSchema("schema_example1");
export const schema2 = getNewSchema("schema_example2");
import { ColumnBuilderBaseConfig, ColumnDataType } from "drizzle-orm";
import { PgColumnBuilderBase, pgSchema, pgTable, serial, text, varchar } from "drizzle-orm/pg-core";

export const configSchema = pgSchema("config");
export const UserConfig = configSchema.table("user_config", {
id: serial("id").primaryKey(),

email: varchar("email", { length: 255 }).notNull().unique(),
password: varchar("password", { length: 255 }),

schema: text("schema"),
});

export function getNewSchema(schema: string) {
const modelSchema = pgSchema(schema);

const Users = modelSchema.table("user", {
id: serial("id").primaryKey(),

name: text("name"),
});

const Contracts = modelSchema.table("contract", {
id: serial("id").primaryKey(),
});

const exampleTable = modelSchema.table("example_table", {
id: serial("id").primaryKey(),
});

return { Users, Contracts, exampleTable };
// ^^^^^^^^^^ this.
}

export const schema1 = getNewSchema("schema_example1");
export const schema2 = getNewSchema("schema_example2");
3 replies