---
# System prepended metadata

title: Wille - Will
tags: [wille]

---

# Wille - Will
###### tags: `wille`

## Kreiranje patch-eva i changelog-ova
1. Potrebno je da postoji kreiran **will** psql user
```sql=
psql postgres -U postgres -c "create USER will with PASSWORD 'will'";
```
2.  Kreiramo **will_prod_schema** bazu podataka u kojoj će biti kreirana šema sa produkcije
```sql=
psql postgres -U postgres -c "select pg_terminate_backend(pid) from pg_stat_activity where datname = 'will_prod_schema'"
psql postgres -U postgres -c "drop database if exists will_prod_schema"
psql postgres -U postgres -c "create database will_prod_schema"
psql postgres -U postgres -c "grant all privileges on database will_prod_schema to poa"
```
3. Kreiramo tabele (šemu) sa produkcije
**Na willpriv**:
- docker exec -it will_db_1 /bin/bash
- pg_dump -U will -s > will_prod_schema.sql
- exit
- docker cp will_db_1:will_prod_schema.sql will_prod_schema.sql
- exit
- rsync -avc willpriv:will_prod_schema.sql .
```sql=
psql will_prod_schema -U will < will_prod_schema.sql
```

4. Kreiramo **will_dev_schema** bazu podataka u kojoj će biti kreirana trenutna šema podataka
```sql=
psql postgres -U postgres -c "select pg_terminate_backend(pid) from pg_stat_activity where datname = 'will_dev_schema'"
psql postgres -U postgres -c "drop database if exists will_dev_schema"
psql postgres -U postgres -c "create database will_dev_schema"
psql postgres -U postgres -c "grant all privileges on database will_dev_schema to will"
```

5. Postavljamo prod konfiguraciju tako da kreira celokupnu šemu podataka u will_dev_schema bazi podataka kako bi napravili **diff** trenutne i šeme sa produkcije
```java=
spring.jpa.hibernate.ddl-auto = create
spring.datasource.url=jdbc:postgresql://localhost:5432/will_dev_schema
spring.liquibase.enabled=false
```

**cd wille-will
mvn spring-boot:run -Dspring-boot.run.profiles=prod**

6. Krairamo diff trenutne i šeme sa produkcije u fajlu db.changelog-diff.postgresql.sql
```shell=
mvn liquibase:diff \
-Dliquibase.username=will \
-Dliquibase.url=jdbc:postgresql://localhost:5432/will_prod_schema \
-Dliquibase.referenceUsername=will \
-Dliquibase.referenceUrl=jdbc:postgresql://localhost:5432/will_dev_schema \
-Dliquibase.changeLogFile=src/main/resources/db/changelog/db.changelog-master.yaml \
-Dliquibase.diffChangeLogFile=src/main/resources/db/changelog/db.changelog-diff.postgresql.sql \
-Dliquibase.logging=DEBUG \
-Dliquibase.verbose=true
```

7. Obrisati sve act_ i jv_ changeset-ove iz db.changelog-diff.postgresql.sql

8.  Napraviti patch-eve i changelog fajlove pa ih zatim ukljuciti i u changelog-master (ostaviti db.changelog-diff.postgresql.sql cistim)

9. Vratiti prod konfiguraciju u prethodno stanje

10. Kreiramo will bazu podataka u koju će biti spušten prod will_prod.sql dump
```sql=
psql postgres -U postgres -c "select pg_terminate_backend(pid) from pg_stat_activity where datname = 'will'"
psql postgres -U postgres -c "drop database if exists will"
psql postgres -U postgres -c "create database will"
psql postgres -U postgres -c "grant all privileges on database will to will"
```


11. Kreiramo tabele (šemu ukljucujuci i podatke) sa produkcije
**Na willpriv:**
- docker exec -it will_db_1 /bin/bash
- pg_dump -U will > will_prod.sql
- exit
- docker cp will_db_1:will_prod.sql will_prod.sql
- exit
- rsync -avc willpriv:will_prod.sql .

```sql=
psql will -U will < will_prod.sql
```

12. Pokrenemo aplikaciju i proverimo da li se changelog-ovi kreiraju uspešno, u suprotnom ponoviti postupak dok se ne kreira željena šema
**cd wille-will
mvn spring-boot:run -Dspring-boot.run.profiles=prod**