export const locations = sqliteTable('locations', {
id: text()
.primaryKey()
.$defaultFn(() => nanoid()),
name: text().notNull(),
slug: text().notNull().unique(),
country: text().notNull().default('us'),
});
export const locationsRelations = relations(locations, ({ one, many }) => ({
tags: many(locationsToTags),
}));
export const tags = sqliteTable('tags', {
id: text()
.primaryKey()
.$defaultFn(() => nanoid()),
name: text({ mode: 'json' }).$type<Record<string, string>>().notNull(),
slug: text().notNull().unique(),
});
export const tagsRelations = relations(locations, ({ many }) => ({
locations: many(locationsToTags),
}));
export const locationsToTags = sqliteTable(
'locations_to_tags',
{
locationId: text('location_id')
.notNull()
.references(() => locations.id),
tagId: text('tag_id')
.notNull()
.references(() => tags.id),
},
(t) => ({
pk: primaryKey({ columns: [t.locationId, t.tagId] }),
}),
);
export const locationsToTagsRelations = relations(
locationsToTags,
({ many }) => ({
tags: many(tags),
locations: many(locations),
}),
);
export const locations = sqliteTable('locations', {
id: text()
.primaryKey()
.$defaultFn(() => nanoid()),
name: text().notNull(),
slug: text().notNull().unique(),
country: text().notNull().default('us'),
});
export const locationsRelations = relations(locations, ({ one, many }) => ({
tags: many(locationsToTags),
}));
export const tags = sqliteTable('tags', {
id: text()
.primaryKey()
.$defaultFn(() => nanoid()),
name: text({ mode: 'json' }).$type<Record<string, string>>().notNull(),
slug: text().notNull().unique(),
});
export const tagsRelations = relations(locations, ({ many }) => ({
locations: many(locationsToTags),
}));
export const locationsToTags = sqliteTable(
'locations_to_tags',
{
locationId: text('location_id')
.notNull()
.references(() => locations.id),
tagId: text('tag_id')
.notNull()
.references(() => tags.id),
},
(t) => ({
pk: primaryKey({ columns: [t.locationId, t.tagId] }),
}),
);
export const locationsToTagsRelations = relations(
locationsToTags,
({ many }) => ({
tags: many(tags),
locations: many(locations),
}),
);