Browse Source

reconfiguring database import and adding practice

practices
Simon Bowie 1 year ago
parent
commit
44faa963fd
2 changed files with 6 additions and 5 deletions
  1. +5
    -5
      database_functions.sh
  2. +1
    -0
      web/app/practice.py

+ 5
- 5
database_functions.sh View File



Export() Export()
{ {
docker exec -it $CONTAINER mysqldump --single-transaction -u $USERNAME -p$PASSWORD $DATABASE > $EXPORT_DIRECTORY/$EXPORT_SQL_FILENAME`date +"%Y%m%d"`.sql
docker exec -it $CONTAINER mariadb-dump --single-transaction -u $USERNAME -p$PASSWORD $DATABASE > $EXPORT_DIRECTORY/$EXPORT_SQL_FILENAME`date +"%Y%m%d"`.sql
} }


Import() Import()
{ {
docker exec -i $CONTAINER mysql -u $USERNAME -p$PASSWORD $DATABASE < $IMPORT_SQL_FILE
docker exec -i $CONTAINER mariadb -u $USERNAME -p$PASSWORD $DATABASE < $IMPORT_SQL_FILE
} }


Table_export() Table_export()
{ {
docker exec -it $CONTAINER bash -c "mysql -u $USERNAME -p$PASSWORD $DATABASE --batch -e 'SELECT * FROM $TABLE'" > $EXPORT_TXT_DIRECTORY/$EXPORT_TXT_FILENAME.txt
docker exec -it $CONTAINER bash -c "mariadb -u $USERNAME -p$PASSWORD $DATABASE --batch -e 'SELECT * FROM $TABLE'" > $EXPORT_TXT_DIRECTORY/$EXPORT_TXT_FILENAME.txt
} }


Table_import() Table_import()
{ {
docker cp $IMPORT_TXT_FILE $CONTAINER:/tmp/import_file docker cp $IMPORT_TXT_FILE $CONTAINER:/tmp/import_file


docker exec -i $CONTAINER bash -c "mysql -u $USERNAME -p$PASSWORD $DATABASE -e 'LOAD DATA LOCAL INFILE '\''/tmp/import_file'\'' REPLACE INTO TABLE $TABLE FIELDS TERMINATED BY '\''\t'\'' LINES TERMINATED BY '\''\r'\'' IGNORE 1 ROWS;'"
docker exec -i $CONTAINER bash -c "mariadb -u $USERNAME -p$PASSWORD $DATABASE -e 'LOAD DATA LOCAL INFILE '\''/tmp/import_file'\'' REPLACE INTO TABLE $TABLE FIELDS TERMINATED BY '\''\t'\'' LINES TERMINATED BY '\''\r'\'' IGNORE 1 ROWS;'"
} }


Drop_table() Drop_table()
{ {
docker exec -i $CONTAINER bash -c "mysql -u $USERNAME -p$PASSWORD $DATABASE -e 'DROP TABLE IF EXISTS $TABLE;'"
docker exec -i $CONTAINER bash -c "mariadb -u $USERNAME -p$PASSWORD $DATABASE -e 'DROP TABLE IF EXISTS $TABLE;'"
} }
############################################################ ############################################################
############################################################ ############################################################

+ 1
- 0
web/app/practice.py View File

Resource.id==59, Resource.id==59,
Resource.id==62, Resource.id==62,
Resource.id==63, Resource.id==63,
Resource.id==64,
Resource.id==65, Resource.id==65,
Resource.id==66 Resource.id==66
)) ))

Loading…
Cancel
Save