diff --git a/sql/create_tables.sql b/sql/create_tables.sql index 1b9e05c..35e4865 100644 --- a/sql/create_tables.sql +++ b/sql/create_tables.sql @@ -24,7 +24,6 @@ AS $$ website_id integer, artist_id integer, CONSTRAINT aw_url UNIQUE(url), - CONSTRAINT aw_folder_path UNIQUE(folder_path), CONSTRAINT aw_artist FOREIGN KEY (artist_id) REFERENCES artist (ID), CONSTRAINT aw_website FOREIGN KEY (website_id) REFERENCES website (ID) ); diff --git a/sql/insert_url_with_custom_artist.sql b/sql/insert_url_with_custom_artist.sql index d3e076a..f651735 100644 --- a/sql/insert_url_with_custom_artist.sql +++ b/sql/insert_url_with_custom_artist.sql @@ -16,18 +16,14 @@ BEGIN PERFORM * FROM artist a WHERE a.name = in_artist_name; - IF FOUND THEN - RAISE EXCEPTION 'artist already exists'; + IF NOT FOUND THEN + INSERT INTO artist (name) VALUES (in_artist_name); END IF; - INSERT INTO artist_website (url) VALUES (in_url); - INSERT INTO artist (name) VALUES (in_artist_name); - SELECT artist.id INTO temp_artist_id FROM artist WHERE artist.name = in_artist_name; - UPDATE artist_website SET artist_id = temp_artist_id - WHERE url = in_url; + INSERT INTO artist_website (url, artist_id) VALUES (in_url, temp_artist_id); SELECT * INTO ret_value FROM set_website_name(in_url); IF ret_value <> 0 THEN