Skip to content

Commit

Permalink
sql: create index on foreign key
Browse files Browse the repository at this point in the history
  • Loading branch information
vnghia committed Feb 6, 2024
1 parent e68589c commit 9fbb7c4
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
-- This file should undo anything in `up.sql`
drop index user_music_folder_permissions_user_id_idx;

drop index user_music_folder_permissions_music_folder_id_idx;

drop table user_music_folder_permissions;
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@ create table
constraint user_music_folder_permissions_pkey primary key (user_id, music_folder_id),
constraint user_music_folder_permissions_user_id_fkey foreign key (user_id) references users (id) on delete cascade,
constraint user_music_folder_permissions_music_folder_id_fkey foreign key (music_folder_id) references music_folders (id) on delete cascade
);
);

create index user_music_folder_permissions_user_id_idx on user_music_folder_permissions (user_id);

create index user_music_folder_permissions_music_folder_id_idx on user_music_folder_permissions (music_folder_id);
4 changes: 4 additions & 0 deletions migrations/2024-01-21-014803_create_songs/down.sql
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
-- This file should undo anything in `up.sql`
drop index songs_album_id_idx;

drop index songs_music_folder_id_idx;

drop table songs;
6 changes: 5 additions & 1 deletion migrations/2024-01-21-014803_create_songs/up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@ create table
);

select
add_updated_at_leave_scanned_at ('songs');
add_updated_at_leave_scanned_at ('songs');

create index songs_album_id_idx on songs (album_id);

create index songs_music_folder_id_idx on songs (music_folder_id);
6 changes: 6 additions & 0 deletions migrations/2024-01-21-015739_create_albums_artists/down.sql
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
-- This file should undo anything in `up.sql`
drop index albums_artists_album_id_idx;

drop index albums_artists_artist_id_idx;

drop index albums_artists_song_id_idx;

drop table albums_artists;
8 changes: 7 additions & 1 deletion migrations/2024-01-21-015739_create_albums_artists/up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,10 @@ create table
constraint albums_artists_album_id_fkey foreign key (album_id) references albums (id) on delete cascade,
constraint albums_artists_artist_id_fkey foreign key (artist_id) references artists (id) on delete cascade,
constraint albums_artists_song_id_fkey foreign key (song_id) references songs (id) on delete cascade
);
);

create index albums_artists_album_id_idx on albums_artists (album_id);

create index albums_artists_artist_id_idx on albums_artists (artist_id);

create index albums_artists_song_id_idx on albums_artists (song_id);
4 changes: 4 additions & 0 deletions migrations/2024-01-21-020718_create_songs_artists/down.sql
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
-- This file should undo anything in `up.sql`
drop index songs_artists_song_id_idx;

drop index songs_artists_artist_id_idx;

drop table songs_artists;
6 changes: 5 additions & 1 deletion migrations/2024-01-21-020718_create_songs_artists/up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@ create table
constraint songs_artists_pkey primary key (song_id, artist_id),
constraint songs_artists_song_id_fkey foreign key (song_id) references songs (id) on delete cascade,
constraint songs_artists_artist_id_fkey foreign key (artist_id) references artists (id) on delete cascade
);
);

create index songs_artists_song_id_idx on songs_artists (song_id);

create index songs_artists_artist_id_idx on songs_artists (artist_id);

0 comments on commit 9fbb7c4

Please sign in to comment.