Tibo
Tibo
Explore posts from servers
DTDrizzle Team
Created by Tibo on 4/18/2024 in #help
Cascade delete not working
I have this schema:
export const albums = pgTable('albums', {
id: uuid('id').notNull().primaryKey().defaultRandom(),
name: text('name').notNull().unique(),

gameId: uuid('game_id').notNull(),
});

export const albumsRelations = relations(albums, ({ one, many }) => ({
music: many(musics),
}));

export const musics = pgTable('musics', {
id: uuid('id').notNull().primaryKey().defaultRandom(),
name: text('name').notNull(),
url: text('url').notNull().unique(),

albumId: uuid('album_id')
.notNull()
.references(() => albums.id, { onDelete: 'cascade' }),
});

export const musicsRelations = relations(musics, ({ one, many }) => ({
album: one(albums, { fields: [musics.albumId], references: [albums.id] }),
musicsToAuthors: many(musicsToAuthors),
}));

export const authors = pgTable('authors', {
id: uuid('id').notNull().primaryKey().defaultRandom(),
name: text('name').notNull().unique(),
});

export const authorsRelations = relations(authors, ({ many }) => ({
musicsToAuthors: many(musicsToAuthors),
}));

// more in first comment
export const albums = pgTable('albums', {
id: uuid('id').notNull().primaryKey().defaultRandom(),
name: text('name').notNull().unique(),

gameId: uuid('game_id').notNull(),
});

export const albumsRelations = relations(albums, ({ one, many }) => ({
music: many(musics),
}));

export const musics = pgTable('musics', {
id: uuid('id').notNull().primaryKey().defaultRandom(),
name: text('name').notNull(),
url: text('url').notNull().unique(),

albumId: uuid('album_id')
.notNull()
.references(() => albums.id, { onDelete: 'cascade' }),
});

export const musicsRelations = relations(musics, ({ one, many }) => ({
album: one(albums, { fields: [musics.albumId], references: [albums.id] }),
musicsToAuthors: many(musicsToAuthors),
}));

export const authors = pgTable('authors', {
id: uuid('id').notNull().primaryKey().defaultRandom(),
name: text('name').notNull().unique(),
});

export const authorsRelations = relations(authors, ({ many }) => ({
musicsToAuthors: many(musicsToAuthors),
}));

// more in first comment
When I try to delete all the musics from an album I get this error: update or delete on table "musics" violates foreign key constraint "musics_to_authors_music_id_musics_id_fk" on table "musics_to_authors" Here's my delete: await db.delete(musics).where(eq(musics.albumId, albumId)) I don't understand what I'm doing wrong
6 replies
DTDrizzle Team
Created by Tibo on 3/29/2024 in #help
TypeError: Cannot read properties of undefined (reading 'compositePrimaryKeys')
I'm getting this error when I want to rename a table (there are no other changes). Old table:
export const userFavoritesMusics = pgTable(
'user_favorites',
{
userId: text('user_id')
.notNull()
.references(() => users.id, { onDelete: 'cascade' }),
musicId: integer('music_id')
.notNull()
.references(() => musics.id, { onDelete: 'cascade' }),
createdAt: timestamp('created_at').notNull().defaultNow(),
},
(t) => ({
pk: primaryKey(t.userId, t.musicId),
}),
);
export const userFavoritesMusics = pgTable(
'user_favorites',
{
userId: text('user_id')
.notNull()
.references(() => users.id, { onDelete: 'cascade' }),
musicId: integer('music_id')
.notNull()
.references(() => musics.id, { onDelete: 'cascade' }),
createdAt: timestamp('created_at').notNull().defaultNow(),
},
(t) => ({
pk: primaryKey(t.userId, t.musicId),
}),
);
New table:
export const userFavoritesMusics = pgTable(
'user_favorites_musics',
{
userId: text('user_id')
.notNull()
.references(() => users.id, { onDelete: 'cascade' }),
musicId: integer('music_id')
.notNull()
.references(() => musics.id, { onDelete: 'cascade' }),
createdAt: timestamp('created_at').notNull().defaultNow(),
},
(t) => ({
pk: primaryKey(t.userId, t.musicId),
}),
);
export const userFavoritesMusics = pgTable(
'user_favorites_musics',
{
userId: text('user_id')
.notNull()
.references(() => users.id, { onDelete: 'cascade' }),
musicId: integer('music_id')
.notNull()
.references(() => musics.id, { onDelete: 'cascade' }),
createdAt: timestamp('created_at').notNull().defaultNow(),
},
(t) => ({
pk: primaryKey(t.userId, t.musicId),
}),
);
Only the name changed so I don't understand why I'm getting this error. What should I do ?
3 replies
DTDrizzle Team
Created by Tibo on 3/17/2024 in #help
How to do inserts in many-to-many relations ?
I'm new to Drizzle and I don't really know if my tables relation is correct or not. Here's the schema:
export const musics = pgTable('musics', {
id: serial('id').primaryKey(),
url: text('url').notNull().unique(),
number: integer('number').notNull(),
title: text('title').notNull(),
duration: integer('duration').notNull(),
albumId: serial('album_id')
.notNull()
.references(() => albums.id, { onDelete: 'cascade' }),
});

export const musicsRelations = relations(musics, ({ one, many }) => ({
album: one(albums, { fields: [musics.albumId], references: [albums.id] }),
musicsToAuthors: many(musicsToAuthors),
}));

export const authors = pgTable('authors', {
id: serial('id').primaryKey(),
name: text('name').notNull().unique(),
});

export const authorsRelations = relations(authors, ({ many }) => ({
musicsToAuthors: many(musicsToAuthors),
}));

export const musicsToAuthors = pgTable(
'musics_to_authors',
{
musicId: integer('music_id')
.notNull()
.references(() => musics.id),
authorId: integer('author_id')
.notNull()
.references(() => authors.id),
},
(t) => ({
pk: primaryKey(t.musicId, t.authorId),
}),
);

export const musicToAuthorRelations = relations(musicsToAuthors, ({ one }) => ({
music: one(musics, {
fields: [musicsToAuthors.musicId],
references: [musics.id],
}),
author: one(authors, {
fields: [musicsToAuthors.authorId],
references: [authors.id],
}),
}));
export const musics = pgTable('musics', {
id: serial('id').primaryKey(),
url: text('url').notNull().unique(),
number: integer('number').notNull(),
title: text('title').notNull(),
duration: integer('duration').notNull(),
albumId: serial('album_id')
.notNull()
.references(() => albums.id, { onDelete: 'cascade' }),
});

export const musicsRelations = relations(musics, ({ one, many }) => ({
album: one(albums, { fields: [musics.albumId], references: [albums.id] }),
musicsToAuthors: many(musicsToAuthors),
}));

export const authors = pgTable('authors', {
id: serial('id').primaryKey(),
name: text('name').notNull().unique(),
});

export const authorsRelations = relations(authors, ({ many }) => ({
musicsToAuthors: many(musicsToAuthors),
}));

export const musicsToAuthors = pgTable(
'musics_to_authors',
{
musicId: integer('music_id')
.notNull()
.references(() => musics.id),
authorId: integer('author_id')
.notNull()
.references(() => authors.id),
},
(t) => ({
pk: primaryKey(t.musicId, t.authorId),
}),
);

export const musicToAuthorRelations = relations(musicsToAuthors, ({ one }) => ({
music: one(musics, {
fields: [musicsToAuthors.musicId],
references: [musics.id],
}),
author: one(authors, {
fields: [musicsToAuthors.authorId],
references: [authors.id],
}),
}));
I chose to use a many-to-many relation because a music can have multiple authors and an author can have multiple music. Is my schema correct ? Insert in comment
2 replies
RRailway
Created by Tibo on 3/8/2024 in #✋|help
Error when running start command for SvelteKit app
I want to deploy my Sveltekit app on Railway but I'm getting errors during the deployment. Here's my deployment log:
npx http-server ./dist
npm WARN config production Use `--omit=dev` instead.
npm WARN exec The following package was not found and will be installed: [email protected]
Starting up http-server, serving ./dist
http-server version: 14.1.1
http-server settings:
CORS: disabled
Cache: 3600 seconds
Connection Timeout: 120 seconds
Directory Listings: visible
AutoIndex: visible
Serve GZIP Files: false
Serve Brotli Files: false
Default File Extension: none
Available on:
http://127.0.0.1:5882
http://172.17.2.98:5882
Hit CTRL-C to stop the server
[2024-03-08T13:27:04.136Z] "GET /" "Mozilla/5.0 (X11; Linux x86_64; rv:122.0) Gecko/20100101 Firefox/122.0"
(node:145) [DEP0066] DeprecationWarning: OutgoingMessage.prototype._headers is deprecated
(Use `node --trace-deprecation ...` to show where the warning was created)
"GET /" Error (404): "Not found"
"GET /favicon.ico" "Mozilla/5.0 (X11; Linux x86_64; rv:122.0) Gecko/20100101 Firefox/122.0"
npx http-server ./dist
npm WARN config production Use `--omit=dev` instead.
npm WARN exec The following package was not found and will be installed: [email protected]
Starting up http-server, serving ./dist
http-server version: 14.1.1
http-server settings:
CORS: disabled
Cache: 3600 seconds
Connection Timeout: 120 seconds
Directory Listings: visible
AutoIndex: visible
Serve GZIP Files: false
Serve Brotli Files: false
Default File Extension: none
Available on:
http://127.0.0.1:5882
http://172.17.2.98:5882
Hit CTRL-C to stop the server
[2024-03-08T13:27:04.136Z] "GET /" "Mozilla/5.0 (X11; Linux x86_64; rv:122.0) Gecko/20100101 Firefox/122.0"
(node:145) [DEP0066] DeprecationWarning: OutgoingMessage.prototype._headers is deprecated
(Use `node --trace-deprecation ...` to show where the warning was created)
"GET /" Error (404): "Not found"
"GET /favicon.ico" "Mozilla/5.0 (X11; Linux x86_64; rv:122.0) Gecko/20100101 Firefox/122.0"
The problem seems to come from my start command. As I'm using Vite, there are no built-in start command so I used this one: npx http-server ./dist I don't know what I should use as a start command or what I should modify
4 replies
RRailway
Created by Tibo on 2/18/2024 in #✋|help
Add a GCP key json file
I'm using Google Cloud Storage and I connect to it with a json file containing the key. This file is not in my repo so it's not added to the build. I'd like to know if it's possible to add a file outside the git repo to the build ?
7 replies
RRailway
Created by Tibo on 11/6/2023 in #✋|help
Can't connect environment to a specific branch
I have a project with a production environment and I'd like to link it to the branch 'main' of my GitHub repo. The project is already connected to this repo and is redeployed every time I push to one of the branch but when I click on the button 'Connect environment to branch' I'm getting an error saying that the repo could not be found.
5 replies
CDCloudflare Developers
Created by Tibo on 11/4/2023 in #pages-help
Unable to deploy my NextJS app
I'm trying to deploy my NextJS app to Cloudflare pages but I'm getting an error because it can't find some modules. I followed this guide: https://developers.cloudflare.com/pages/framework-guides/deploy-a-nextjs-site/ It's my first build after adding my site to Cloudflare pages.
1 replies