abnDK / personal-budget-2

For completing personal budget 2 project in Codecademy back engineer career path
0 stars 0 forks source link

reset_tables.sh will drop and recreate entire database #17

Closed abnDK closed 1 year ago

abnDK commented 1 year ago

In order to remove all constraints, sequences and other stuff being created with the creation of tables, it is better to drop the entire database and rebuild it. this should be optional and stated using a flag when running reset_tables.sh

Code should be placed in reset_database.sh and run from reset_tables.sh

First: run psql as -u abndk and -f drop_database.sql

drop_database.sql: DROP DATABASE personal_budget_2;

Then: run psql as -u abndk and -f create_database.sql

create_database.sql: CREATE DATABASE personal_budget_2;

After calling reset_database from reset_tables, add line to create tables using psql -f db_1-0.sql

abnDK commented 1 year ago

reset_tables now resets database.

Need to make it optional - but in what cases does it makes sense not to drop the entire thing and instead down migrate from x-x to 1-0 and trying to delete sequences etc? Is the any situations, where i wanna keep the data? Is this solely for testing? Can i preserve data in other ways?

How can i copy data to a copy-database. Reset entire database. Recreate database and insert data from copy-database? What kind of complexities will i run into with data traversing multiple versions when migrating up/down?

abnDK commented 1 year ago

possible changes when migrating:

abnDK commented 1 year ago

if i was to make a copy-database it should

abnDK commented 1 year ago

reset_tables now renames the old database to "_old" and creates a new database.

It is then possible to transfer data from the old version to new version.

Add function for transfering data from the old database to the new version.

abnDK commented 1 year ago

Analysis for transferring data between databases:

abnDK commented 1 year ago

if ./reset_tables.sh is called with 'data' in position 1, data will be transfered to new db

Find out how to order tables so tables who a referenced by other tables will be processed first, then FKEY tables after. Maybe look into pg_constraint's type column?

abnDK commented 1 year ago

if ./reset_tables.sh is called with 'data' in position 1, data will be transfered to new db

Find out how to order tables so tables who a referenced by other tables will be processed first, then FKEY tables after. Maybe look into pg_constraint's type column?

Design of a solution, that orders data export and import in a way, that processes parent tables before children tables (with fkey relation to parent tables)

table a -- table b -- table c

import order: a, b, c

table A -- table B -- table C ---- table D -- table E

import order: a, b, c, e, d

Solution will follow the order of generations: grandparents, then parents, then children and so forth.

abnDK commented 1 year ago

First part - getting parents and children relationship can be done with "psql -f foreign_key_constraints.sql"

Still need to find a way to order the tables and then run the export/import of data from that list.

abnDK commented 1 year ago

Is done now with sort_tables.js etc.