Skip to content

Commit

Permalink
Added part_relationships table
Browse files Browse the repository at this point in the history
  • Loading branch information
jncraton committed Nov 18, 2017
1 parent 5942c8e commit b2795d7
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
6 changes: 6 additions & 0 deletions examples.sql
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,9 @@ where part_num = 3004;
select part_num, year_from, year_to, num_sets, num_set_parts, part_img_url
from part_color_info
where part_num = 3004 and color_id=10;

-- List the part ids for 1 x 1 Clip Vertical

select child_part_num
from part_relationships
where parent_part_num = 4085;
2 changes: 1 addition & 1 deletion makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ all: $(sqldump)
$(sqldump): $(db)
sqlite3 $(db) .dump > $(sqldump)

$(db): tables/themes.csv tables/colors.csv tables/part_categories.csv tables/parts.csv tables/inventories.csv tables/sets.csv tables/inventory_parts.csv tables/inventory_sets.csv src/rb_import/schema.sql src/rb_import/import.sql
$(db): tables/themes.csv tables/colors.csv tables/part_categories.csv tables/parts.csv tables/part_relationships.csv tables/inventories.csv tables/sets.csv tables/inventory_parts.csv tables/inventory_sets.csv src/rb_import/schema.sql src/rb_import/import.sql
sqlite3 $(db) < src/rb_import/schema.sql
sqlite3 $(db) < src/rb_import/import.sql

Expand Down
2 changes: 2 additions & 0 deletions src/rb_import/import.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ delete from inventory_sets;
delete from inventory_parts;
delete from inventories;
delete from sets;
delete from part_relationships;
delete from parts;
delete from part_categories;
delete from colors;
Expand All @@ -16,6 +17,7 @@ delete from themes;
.import tables/colors.csv colors
.import tables/part_categories.csv part_categories
.import tables/parts.csv parts
.import tables/part_relationships.csv part_relationships
.import tables/sets.csv sets
.import tables/inventories.csv inventories
.import tables/inventory_parts.csv inventory_parts
Expand Down
9 changes: 9 additions & 0 deletions src/rb_import/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ create table if not exists parts (
foreign key(part_cat_id) references part_categories(id)
);

create table if not exists part_relationships (
rel_type varchar(1),
child_part_num varchar(16),
parent_part_num varchar(16)
--TODO: foreign key constraints currently fail on this table
--foreign key(child_part_num) references parts(part_num)
--foreign key(parent_part_num) references parts(part_num)
);

create table if not exists inventories (
id int primary key,
version smallint,
Expand Down

0 comments on commit b2795d7

Please sign in to comment.