Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
9f6e36b
updated .jar and liquibase config to fit current database and liquiba…
nboard Apr 18, 2023
7f42878
updated parse_ddl.pl to make changes for indexes match between .sql a…
nboard Apr 21, 2023
373e8da
changed jsonCompare.py to allow for 2 source files, one from parse_dd…
nboard Apr 24, 2023
09c8903
cleaned up perl scripts a bit
nboard Apr 27, 2023
4b7ce10
Updated how jsonCompare.py handles primary keys and fixed a few bugs.…
nboard May 2, 2023
dd5b951
changed how column drops are handled. Added ability to change column …
nboard May 5, 2023
3db14de
Started add/delete logic to jsonCompare.py (WARNING: currently has a …
nboard May 16, 2023
ea1cadd
Changed the way jsonCompare handles adding columns, and added ability…
nboard May 17, 2023
7199318
added table drops and renames. Reworked how table adds are handled. A…
nboard May 23, 2023
7165ba7
updated jsonCompare.py with the following: Updated how columns are ad…
nboard May 24, 2023
666f856
Updated error handling in jsonCompare.py and updated it to delete ind…
nboard Jun 5, 2023
a212fed
fixed how jsonCompare.py updates column orders
nboard Jun 5, 2023
c870622
added rollbacks for dropping columns, updating primary keys, reorderi…
nboard Jun 8, 2023
5956f03
Added dictionary to track column name changes. Added incomplete funct…
nboard Jun 26, 2023
d367a56
updated instruction for liquibase. Continued work on jsonCompare.py's…
nboard Jun 27, 2023
272849d
add a helper function genAttrString to make adding attributes to type…
nboard Jun 30, 2023
499a3cc
saving current state before reworking attributeColumnDif
nboard Jul 5, 2023
eb6dfcc
updated code to handle constraints as well. NOTE: constraints current…
nboard Jul 7, 2023
861aecf
Fixed unique constraint to work properly in multiple situations. Upda…
nboard Jul 11, 2023
4e1add0
Fixed a few minor bugs in jsonCompare.py. Set a new start for the liq…
nboard Jul 14, 2023
cbd8323
Fixed bug with jsonCompare.py losing attributes/constraints when rena…
nboard Jul 19, 2023
d9e4235
Updated how unique indexes are handled by parse_ddl.pl and jsonCompar…
nboard Jul 25, 2023
5535c1a
Updated how jsonCompare.py handles indexes, unique constraints, and r…
nboard Jul 28, 2023
8b3da5e
Updated documentation for liquibase. Updated how table rename, drops,…
nboard Aug 8, 2023
d144b25
Updated liquibase documentation to include limitations
nboard Aug 8, 2023
147181e
Updated liquibase documentation to remove inaccurate statement
nboard Aug 8, 2023
6dd2af1
Merge branch 'master' into liquibase_update before pull request
nboard Aug 8, 2023
cdcc2e4
Updated parse_ddl.pl to ignore default values on columns when creatin…
nboard Sep 13, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 0 additions & 31 deletions kardia-db/Liquibase instructions.txt

This file was deleted.

94 changes: 94 additions & 0 deletions kardia-db/LiquibaseInstructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
## Download Instructions:
1. Download the lastest version of Liquibase at: https://download.liquibase.org/download/?frm=n
2. Follow Liquibase install instructions
3. Test that you can use Liquibase by using the command ```liquibase --version``` in the command line

a. If this does not work, check that your PATH variable is properly set and check that you have the latest version of java
4. Download Perl and Python
<br>

## How to use Liquibase:
1. Look at Liquibase.properties (located at ```kardia/kardia-db/ddl-[database]```) and make sure the information is correct.
a. The driver and classpath should not need to be changed.
b. The url should look something like this: ```jdbc:jtds:sybase//localhost:3306/Kardia_DB``` for sybase (```jdbc:mariadb://...``` for mysql)
&nbsp;&nbsp;&nbsp;&nbsp;**NOTE:** localhost should be changed to the machine running Kardia if not localhost

c. Add lines for username and password for machine if desired (username: myUsername and password: myPassword)
2. Use the command line to navigate to ```kardia/kardia-db/ddl-[database]```
3. Get the full changeLog of the current database with the following command:
```
liquibase generateChangeLog --changeLogFile liquibaseFiles/currentChangeLog.json
```
a. Use the ```--username``` and ```--password``` tags if they are not in the .properties file

b. If the currentChangeLog.json file already exists, include the ```--overwrite-output-file``` tag
4. Navigate up a folder to ```kardia/kardia-db```
5. Get the database schema from the wiki by running:
```
perl parse_ddl.pl -b [database] -n
```
**NOTE:** to include the dropdown tables and data, also run:
```
perl make_dropdowns.pl [database]
```
6. enerate the differences between the schema in the current database and the wiki by running the following:
```
python jsonCompare.py [database]
```
**NOTE:** If tables need to be dropped, the resulting changeset will be placed in a seperate file to avoid the accidental loss of data, and to make double checking which tables are being dropped far more convenient.
7. Edit masterChangeLog.json (located at ```kardia/kardia-db/ddl-[database]/liquibaseFiles```) to include the newly created json file
8. Navigate to ```kardia/kardia-db/ddl-[database]``` in the command line
9. Update the current database with the following command:
```
liquibase update --changeLogFile liquibaseFiles/masterChangeLog.json
```
<br>

### Rollbacks using Liquibase:
There are 3 main options to rollback a database schema using Liquibase.
Option 1:
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Use "liquibase rollback [tag]" to rollback to the changeSet with the given tag
Option 2:
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Use "liquibase rollback-to-date [date]" to rollback to the given datetime
Option 3:
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Use "liquibase rollback-count --count=[num]" to rollback num changeSets
<br>
## Rules for automated changes with jsonCompare.py:
1. Do NOT mix reordering columns with column adds, renames, or drops
2. Do NOT mix dropping columns with column adds, renames, or reordering
3. Do NOT add a column adjacent to a renamed column
4. Do NOT reame a column to or add a column with the old name of a column that has been renamed in this same set of changes
5. Do NOT have the primary key order and the column order in a table differ.
6. Do NOT create indexes which are the same as the primary key for that table
**Note:** Rules 1 through 4 apply to changes on a single table, while rule 5 applies to the ordering of columnss within a table.

These rules are designed to keep changest to tables conisting of renames, adds, drops, and reorderings from reaching ambiguous states
- Operations like changing data types or changing primary keys will not conflict and are thus not considered
- Rules 1 and 2 remove a significant amount of ambiguity, and should be unobtrusive given they are rarer operations
- Rule 3 is meant to prevent ambiguous cases such as:
```
ABC -> ABDE (A>A, B>B, C>D, +E | A>A, B>B, +D, C>E
```
- Rule 4 is mainly meant to prevent 2 types of ambiguous cases:

a) changing to an old column name as in:
```
ABC -> XACY ( A>X, B>A, C>C, +Y | +X, A>A, B>C, C>Y)
```
b) adding a new column with the name of an old column:
```
ABC -> XYCABZ (+X, +Y, +C, A>A, B>B, C>Z | A>X, B>Y, C>C, +A, +B, +Z)
```
Or any mixture of the two, or any case that could be confused with simply reordering columns
- Rule 5 is the result of a limitation with the way Liquibase handles primary keys. The order of composite keys can only differ from the table's column order if the PK is added after the table is created. This creates problems with the current workflow. Furthermore, the changelog generation for the current schema does not indicate what order the columns in a composite PK are, meaning in order to support it additional work would need to be done.
- Rule 6 is the result of the fact that liquibase ignores index that are redundant to the PK for the table when generating the current changelog, while the wiki changelog generated by the perl scripts will show it. Because of this, jsonCompare.py would interpret this as the index being missing, and will attempt to add it again. When run b liquibase, this command would fail (since the index exists), making the changelog unable to finish running.

If a change needs to be made that breaks one or more of the above rules, the change can still be made by creating a changelog manually. Once the changelog is created, follow steps 7 and onward ("How to use Liquibase", above) to apply the changes.
Alternatively, breaking up the desired illegal change into multiple legal changes may be possible. For example, while the change AB --> BX (A>B, B>X) is illegal (rule 4), creating one changeset with AB --> AX and then creating one with AX --> BX is fine.

## Limitations:

Currently, the liquibase set up has the following limitations:

- The scripts can only generate changelogs for mariadb databases
- The current setup assumes an existing database with proper grants already performed. This is part of the reason why sql scripts are still generated by parse_ddl.pl
6 changes: 0 additions & 6 deletions kardia-db/ddl-mysql/Liquibase.properties

This file was deleted.

Loading