-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
01d8404
commit d86ac68
Showing
8 changed files
with
149 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
create table category (id bigint not null auto_increment, description varchar(255), primary key (id)) engine=InnoDB; | ||
create table ingredient (id bigint not null auto_increment, amount decimal(19,2), description varchar(255), recipe_id bigint, uom_id bigint, primary key (id)) engine=InnoDB; | ||
create table notes (id bigint not null auto_increment, recipe_notes longtext, recipe_id bigint, primary key (id)) engine=InnoDB; | ||
create table recipe (id bigint not null auto_increment, cook_time integer, description varchar(255), difficulty varchar(255), directions longtext, image longblob, prep_time integer, servings integer, source varchar(255), url varchar(255), notes_id bigint, primary key (id)) engine=InnoDB; | ||
create table recipe_category (recipe_id bigint not null, category_id bigint not null, primary key (recipe_id, category_id)) engine=InnoDB; | ||
create table unit_of_measure (id bigint not null auto_increment, description varchar(255), primary key (id)) engine=InnoDB; | ||
alter table ingredient add constraint FKj0s4ywmqqqw4h5iommigh5yja foreign key (recipe_id) references recipe (id); | ||
alter table ingredient add constraint FK6iv5l89qmitedn5m2a71kta2t foreign key (uom_id) references unit_of_measure (id); | ||
alter table notes add constraint FKdbfsiv21ocsbt63sd6fg0t3c8 foreign key (recipe_id) references recipe (id); | ||
alter table recipe add constraint FK37al6kcbdasgfnut9xokktie9 foreign key (notes_id) references notes (id); | ||
alter table recipe_category add constraint FKqsi87i8d4qqdehlv2eiwvpwb foreign key (category_id) references category (id); | ||
alter table recipe_category add constraint FKcqlqnvfyarhieewfeayk3v25v foreign key (recipe_id) references recipe (id); |
95 changes: 95 additions & 0 deletions
95
src/main/java/com/recipe/app/bootstrap/BootStrapMySQL.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package com.recipe.app.bootstrap; | ||
|
||
import com.recipe.app.domain.Category; | ||
import com.recipe.app.domain.UnitOfMeasure; | ||
import com.recipe.app.repositories.CategoryRepository; | ||
import com.recipe.app.repositories.UnitOfMeasureRepository; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.context.ApplicationListener; | ||
import org.springframework.context.annotation.Profile; | ||
import org.springframework.context.event.ContextRefreshedEvent; | ||
import org.springframework.stereotype.Component; | ||
|
||
/** | ||
* Created by alex.andrade on 15/03/2018. | ||
*/ | ||
@Slf4j | ||
@Component | ||
@Profile({"dev", "prod"}) | ||
public class BootStrapMySQL implements ApplicationListener<ContextRefreshedEvent> { | ||
private final CategoryRepository categoryRepository; | ||
private final UnitOfMeasureRepository unitOfMeasureRepository; | ||
|
||
public BootStrapMySQL(CategoryRepository categoryRepository, | ||
UnitOfMeasureRepository unitOfMeasureRepository) { | ||
this.categoryRepository = categoryRepository; | ||
this.unitOfMeasureRepository = unitOfMeasureRepository; | ||
} | ||
|
||
@Override | ||
public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) { | ||
|
||
if (categoryRepository.count() == 0L){ | ||
log.debug("Loading Categories"); | ||
loadCategories(); | ||
} | ||
|
||
if (unitOfMeasureRepository.count() == 0L){ | ||
log.debug("Loading UOMs"); | ||
loadUom(); | ||
} | ||
} | ||
|
||
private void loadCategories(){ | ||
Category cat1 = new Category(); | ||
cat1.setDescription("American"); | ||
categoryRepository.save(cat1); | ||
|
||
Category cat2 = new Category(); | ||
cat2.setDescription("Italian"); | ||
categoryRepository.save(cat2); | ||
|
||
Category cat3 = new Category(); | ||
cat3.setDescription("Mexican"); | ||
categoryRepository.save(cat3); | ||
|
||
Category cat4 = new Category(); | ||
cat4.setDescription("Fast Food"); | ||
categoryRepository.save(cat4); | ||
} | ||
|
||
private void loadUom(){ | ||
UnitOfMeasure uom1 = new UnitOfMeasure(); | ||
uom1.setDescription("Teaspoon"); | ||
unitOfMeasureRepository.save(uom1); | ||
|
||
UnitOfMeasure uom2 = new UnitOfMeasure(); | ||
uom2.setDescription("Tablespoon"); | ||
unitOfMeasureRepository.save(uom2); | ||
|
||
UnitOfMeasure uom3 = new UnitOfMeasure(); | ||
uom3.setDescription("Cup"); | ||
unitOfMeasureRepository.save(uom3); | ||
|
||
UnitOfMeasure uom4 = new UnitOfMeasure(); | ||
uom4.setDescription("Pinch"); | ||
unitOfMeasureRepository.save(uom4); | ||
|
||
UnitOfMeasure uom5 = new UnitOfMeasure(); | ||
uom5.setDescription("Ounce"); | ||
unitOfMeasureRepository.save(uom5); | ||
|
||
UnitOfMeasure uom6 = new UnitOfMeasure(); | ||
uom6.setDescription("Each"); | ||
unitOfMeasureRepository.save(uom6); | ||
|
||
UnitOfMeasure uom7 = new UnitOfMeasure(); | ||
uom7.setDescription("Pint"); | ||
unitOfMeasureRepository.save(uom7); | ||
|
||
UnitOfMeasure uom8 = new UnitOfMeasure(); | ||
uom8.setDescription("Dash"); | ||
unitOfMeasureRepository.save(uom8); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
spring.datasource.platform=h2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
spring: | ||
datasource: | ||
url: jdbc:mysql://192.168.99.100:3306/sfg_dev | ||
username: sfg_dev_user | ||
password: sfg_dev_user | ||
platform: mysql | ||
jpa: | ||
hibernate: | ||
ddl-auto: validate | ||
database-platform: org.hibernate.dialect.MySQL5InnoDBDialect | ||
database: mysql | ||
show-sql: true | ||
|
||
#####Automatic load the database schema | ||
# properties: | ||
# javax: | ||
# persistence: | ||
# schema-generation: | ||
# create-source: metadata | ||
# scripts: | ||
# action: create | ||
# create-target: guru_database_create.sql |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
spring: | ||
datasource: | ||
url: jdbc:mysql://192.168.99.100:3306/sfg_prod | ||
username: sfg_prod_user | ||
password: sfg_prod_user | ||
platform: mysql | ||
jpa: | ||
hibernate: | ||
ddl-auto: validate | ||
database-platform: org.hibernate.dialect.MySQL5InnoDBDialect | ||
database: mysql | ||
show-sql: false |
File renamed without changes.