-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Data Migration Script Draft #19
Open
jersey1dev
wants to merge
11
commits into
Greenstand:main
Choose a base branch
from
jersey1dev:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
f5ddb27
data migration scripts
sole1907 18ed179
updated queries and added max iterations config
sole1907 7d2623e
allow selection of columns to migrate
sole1907 bfb6c4c
variable name changes and typo fixed, makes the exit control flow nicer
jersey1dev ec27c15
WIP: trying to make the logic nicer
jersey1dev 25c7547
trying to do a complete rewrite
jersey1dev 89d583b
rewrite the migration process and reconciled table differences in col…
jersey1dev 21bbc88
removed comments
jersey1dev 652c11b
filter data by entity_id
jersey1dev f5e39cb
removed myenv/
jersey1dev 4c37ea7
clean ups
jersey1dev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
# Editors | ||
.vscode/ | ||
.idea/ | ||
|
||
# Vagrant | ||
.vagrant/ | ||
|
||
# Mac/OSX | ||
.DS_Store | ||
|
||
# Windows | ||
Thumbs.db | ||
|
||
# Source for the following rules: https://raw.githubusercontent.com/github/gitignore/master/Python.gitignore | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
MANIFEST | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.nox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
.hypothesis/ | ||
.pytest_cache/ | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
local_settings.py | ||
db.sqlite3 | ||
|
||
# Flask stuff: | ||
instance/ | ||
.webassets-cache | ||
|
||
# Scrapy stuff: | ||
.scrapy | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
target/ | ||
|
||
# Jupyter Notebook | ||
.ipynb_checkpoints | ||
|
||
# IPython | ||
profile_default/ | ||
ipython_config.py | ||
|
||
# pyenv | ||
.python-version | ||
|
||
# celery beat schedule file | ||
celerybeat-schedule | ||
|
||
# SageMath parsed files | ||
*.sage.py | ||
|
||
# Environments | ||
.env | ||
.venv | ||
env/ | ||
venv/ | ||
ENV/ | ||
env.bak/ | ||
venv.bak/ | ||
|
||
# Spyder project settings | ||
.spyderproject | ||
.spyproject | ||
|
||
# Rope project settings | ||
.ropeproject | ||
|
||
# mkdocs documentation | ||
/site | ||
|
||
# mypy | ||
.mypy_cache/ | ||
.dmypy.json | ||
dmypy.json | ||
|
||
*.txt |
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,42 @@ | ||
Run the following command to create a virtual environment (replace myenv with your preferred name): | ||
`python3 -m venv myenv` | ||
|
||
## Activate the virtual environment: | ||
|
||
#### On Windows: `myenv\Scripts\activate` | ||
|
||
#### On macOS/Linux: `source myenv/bin/activate` | ||
|
||
## Install requirements | ||
|
||
`pip install -r requirements.txt` | ||
|
||
## Set up Database Access Credential in .env | ||
|
||
Create an .env file in the project directory to configure your database login credentials. | ||
|
||
`touch .env` | ||
|
||
Edit the .env file and copy the following key-value configs, update the values according to your actual database access credential. | ||
|
||
``` | ||
SRC_DB_HOST=localhost | ||
SRC_DB_PORT=5432 | ||
SRC_DB_NAME=mydatabase | ||
SRC_DB_USER=myuser | ||
SRC_DB_PASSWORD=mypassword | ||
|
||
DEST_DB_HOST=localhost | ||
DEST_DB_PORT=5432 | ||
DEST_DB_NAME=mydatabase | ||
DEST_DB_USER=myuser | ||
DEST_DB_PASSWORD=mypassword | ||
``` | ||
|
||
## Activate Environment Variables: | ||
|
||
Activate the environment variables by sourcing the .env file in your terminal: `source .env` | ||
|
||
## Run Application: | ||
|
||
Run the application using: `python migration_job.py` |
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,35 @@ | ||
#section name job - job configs | ||
[job] | ||
# here job is scheduled to run every 24 hours, set value to preferred frequency | ||
job_interval_seconds=5 | ||
# number of iterations to run (0) means to run continuously, unless manually stopped | ||
max_iterations=1 | ||
# set batch size for each run, 1000 here means a limit of 1000 records per batch of query | ||
query_batch_size=1000 | ||
# list of organization_ids separated by commas | ||
organization_ids=3312 #15,1,13,14,2,3,4,5,6,30,31,32,11 | ||
|
||
#section name queries | ||
[queries] | ||
#[columns] will be replaced by list of columns specified in columns section below | ||
organization_query=SELECT [columns] FROM entity WHERE entity.id > %s and (type = 'o' or type = 'O') and entity.id in (%s) ORDER BY entity.id LIMIT %s; | ||
planter_query=SELECT [columns] FROM planter, entity WHERE planter.id > %s and entity.id = planter.organization_id and (entity.type = 'o' or entity.type = 'O') and planter.organization_id in (%s) ORDER BY planter.id LIMIT %s; | ||
tree_query=SELECT [columns] FROM trees, planter, entity WHERE trees.id > %s and planter_id = planter.id and entity.id = planter.organization_id and (entity.type = 'o' or entity.type = 'O') and entity.id in (%s) ORDER BY trees.id LIMIT %s; | ||
|
||
#section name columns: columns to migrate | ||
[columns] | ||
organization_columns=entity.id, entity.type, entity.name, entity.first_name, entity.last_name, entity.email, entity.phone, | ||
entity.pwd_reset_required, entity.website, entity.wallet, entity.password, entity.salt, entity.active_contract_id, | ||
entity.offering_pay_to_plant, entity.tree_validation_contract_id, entity.logo_url, entity.map_name, | ||
entity.stakeholder_uuid | ||
planter_columns=planter.id, planter.first_name, planter.last_name, planter.email, planter.organization, planter.phone, | ||
planter.pwd_reset_required, planter.image_url, planter.person_id, planter.organization_id, planter.image_rotation, | ||
planter.gender, planter.grower_account_uuid | ||
tree_columns=trees.id, trees.time_created, trees.time_updated, trees.missing, trees.priority, trees.cause_of_death_id, | ||
trees.planter_id, trees.primary_location_id, trees.settings_id, trees.override_settings_id, trees.dead, trees.photo_id, | ||
trees.image_url, trees.certificate_id, trees.estimated_geometric_location, trees.lat, trees.lon, trees.gps_accuracy, | ||
trees.active, trees.planter_photo_url, trees.planter_identifier, trees.device_id, trees.note, trees.verified, | ||
trees.uuid, trees.approved, trees.status, trees.cluster_regions_assigned, trees.species_id, | ||
trees.planting_organization_id, trees.payment_id, trees.contract_id, trees.token_issued, trees.morphology, trees.age, | ||
trees.species, trees.capture_approval_tag, trees.rejection_reason, trees.matching_hash, trees.device_identifier, | ||
trees.images, trees.domain_specific_data, trees.token_id, trees.name, trees.earnings_id, trees.session_id |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel you don't need these settings anymore, right?