|
| 1 | +COPY users (id, password_hash, name, balance) |
| 2 | +FROM '/store-init-csvs/init-data-users.csv' |
| 3 | +WITH (FORMAT CSV, HEADER, DELIMITER ','); |
| 4 | + |
| 5 | +COPY tags(id, name) |
| 6 | +FROM '/store-init-csvs/init-data-tags.csv' |
| 7 | +WITH (FORMAT CSV, HEADER, DELIMITER ','); |
| 8 | + |
| 9 | +COPY studios(id, name) |
| 10 | +FROM '/store-init-csvs/init-data-studios.csv' |
| 11 | +WITH (FORMAT CSV, HEADER, DELIMITER ','); |
| 12 | + |
| 13 | +COPY games(id, name, price, description, brief, studio_id) |
| 14 | +FROM '/store-init-csvs/init-data-games.csv' |
| 15 | +WITH (FORMAT CSV, HEADER, DELIMITER ','); |
| 16 | + |
| 17 | +-- generator can generate duplicates for this categories |
| 18 | +-- COPY game_tags(game_id, tag_id) |
| 19 | +-- FROM '/store-init-csvs/init-data-game-tags.csv' |
| 20 | +-- WITH (FORMAT CSV, HEADER, DELIMITER ','); |
| 21 | + |
| 22 | +-- COPY purchases(id, owner_id, buyer_id, ts, game_id) |
| 23 | +-- FROM '/store-init-csvs/init-data-purchases.csv' |
| 24 | +-- WITH (FORMAT CSV, HEADER, DELIMITER ',', NULL 'NULL'); |
| 25 | + |
| 26 | +-- create temporary table for games pictures to transform csv |
| 27 | +CREATE TEMP TABLE temp4gpictures ( |
| 28 | + id INTEGER PRIMARY KEY, |
| 29 | + name TEXT, |
| 30 | + game_id INTEGER, |
| 31 | + img_type TEXT, |
| 32 | + img_fmt TEXT, |
| 33 | + img TEXT |
| 34 | +); |
| 35 | + |
| 36 | +COPY temp4gpictures |
| 37 | +FROM '/store-init-csvs/init-games-pictures.csv' |
| 38 | +WITH (FORMAT CSV, HEADER); |
| 39 | + |
| 40 | +INSERT INTO games_pictures (id, name, game_id, img_type, img_fmt) |
| 41 | +SELECT |
| 42 | + s.id, |
| 43 | + s.id::TEXT || 'g.' || s.img_fmt as name, |
| 44 | + s.game_id, |
| 45 | + s.img_type, |
| 46 | + s.img_fmt |
| 47 | +FROM |
| 48 | + temp4gpictures s |
| 49 | +ON CONFLICT (id) DO NOTHING; |
| 50 | + |
| 51 | +DROP TABLE temp4gpictures; |
| 52 | +-- end of copy games pictures |
| 53 | + |
| 54 | +-- create temporary table for profile pictures to transform csv |
| 55 | +CREATE TEMP TABLE temp4ppictures ( |
| 56 | + id INTEGER PRIMARY KEY, |
| 57 | + name TEXT, |
| 58 | + user_id INTEGER, |
| 59 | + img_fmt TEXT, |
| 60 | + img TEXT |
| 61 | +); |
| 62 | + |
| 63 | +COPY temp4ppictures |
| 64 | +FROM '/store-init-csvs/init-profile-pictures.csv' |
| 65 | +WITH (FORMAT CSV, HEADER); |
| 66 | + |
| 67 | +INSERT INTO profiles_pictures (id, name, user_id, img_fmt) |
| 68 | +SELECT |
| 69 | + s.id, |
| 70 | + s.id::TEXT || 'p.' || s.img_fmt as name, |
| 71 | + s.user_id, |
| 72 | + s.img_fmt |
| 73 | +FROM |
| 74 | + temp4ppictures s |
| 75 | +ON CONFLICT (id) DO NOTHING; |
| 76 | + |
| 77 | +DROP TABLE temp4ppictures; |
| 78 | +-- end of copy profile pictures |
0 commit comments