Skip to content
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

Dev: Add initial migration and Running migration instruction to README #1133

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

mtreacy002
Copy link
Member

@mtreacy002 mtreacy002 commented Jul 7, 2021

Description

Initiate migration script and add running migration script to README

Fixes #996

Type of Change:

  • Code
  • Documentation

Code/Quality Assurance Only

  • This change requires a documentation update (software upgrade on readme file)
  • New feature (non-breaking change which adds functionality pre-approved by mentors)

How Has This Been Tested?

  1. On initiation of migration script/when contributors running migration script for the first time
    Confirmed that alembic version was added to the local db and the initial version was created under migrations > versions folder
    before running initial migration

Screen Shot 2021-07-07 at 2 11 46 pm

Screen Shot 2021-07-07 at 2 37 27 pm

after running initial migration
Screen Shot 2021-07-07 at 2 20 24 pm copy
Screen Shot 2021-07-07 at 2 36 29 pm

  1. if contributor missed migration version updates

Screen Shot 2021-07-07 at 3 51 11 pm

The local db will be updated one version at a time accordingly
from initial to second revision
Screen Shot 2021-07-07 at 2 24 37 pm

from second to third revision
Screen Shot 2021-07-07 at 3 50 22 pm

  1. When you are making changes by adding attribute/s to an existing db model

Screen Shot 2021-07-07 at 4 13 34 pm

Screen Shot 2021-07-07 at 4 13 42 pm

Screen Shot 2021-07-07 at 2 24 37 pm

  1. When you are making changes by ALTERING EXISTING ATTRIBUTES inside an existing db model
    Example case: User table
    Changes:
    • renaming column name to full_name
    • change password_hash field length from 100 to unspecified

Screen Shot 2021-07-09 at 10 53 07 pm

IMPORTANT Noticed that the auto-generated alembic script IS NOT CORRECT!!.
You MUST MODIFY the script to reflect the intended schema changes. Once you're done, you can run flask db upgrade

Screen Shot 2021-07-09 at 11 37 04 pm

before alteration
Screen Shot 2021-07-09 at 10 59 54 pm
Screen Shot 2021-07-09 at 11 00 39 pm

After alteration (with data successfully preserved)
Screen Shot 2021-07-09 at 11 34 41 pm
Screen Shot 2021-07-09 at 11 34 56 pm

Checklist:

  • My PR follows the style guidelines of this project
  • I have performed a self-review of my own code or materials
  • I have commented my code or provided relevant documentation, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • Any dependent changes have been merged
  • Update Postman API at /docs folder
  • Update Swagger documentation and the exported file at /docs folder
  • Update requirements.txt

Code/Quality Assurance Only

  • My changes generate no new warnings
  • My PR currently breaks something (fix or feature that would cause existing functionality to not work as expected)
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been published in downstream modules

ADDITIONAL NOTE
NA

@mtreacy002 mtreacy002 force-pushed the add-migration branch 2 times, most recently from 21ec10c to 0906f8c Compare July 7, 2021 06:34
@codecov
Copy link

codecov bot commented Jul 7, 2021

Codecov Report

Merging #1133 (21ec10c) into develop (d717c93) will not change coverage.
The diff coverage is 100.00%.

❗ Current head 21ec10c differs from pull request most recent head d0acedd. Consider uploading reports for the commit d0acedd to get more accurate results
Impacted file tree graph

@@           Coverage Diff            @@
##           develop    #1133   +/-   ##
========================================
  Coverage    92.95%   92.95%           
========================================
  Files           38       38           
  Lines         2073     2073           
========================================
  Hits          1927     1927           
  Misses         146      146           
Impacted Files Coverage Δ
run.py 96.15% <100.00%> (ø)

Update README

update readme

apply black

fix typo

include altering existing column
@mtreacy002 mtreacy002 added Category: Documentation/Training Improvements or additions to documentation. Category: Coding Changes to code base or refactored code that doesn't fix a bug. Status: Needs Review PR needs an additional review or a maintainer's review. Type: Enhancement New feature or request. labels Jul 9, 2021
@mtreacy002
Copy link
Member Author

@isabelcosta, @epicadk, @vj-codes, this PR is now ready for a review. Look forward to your feedback 😉.

```
where `<message>` is a clear message what the change was about. This will be your alembic version title.
You should see the new version inside the `versions` folder
3. run the following command to apply the update to your local db
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
3. run the following command to apply the update to your local db
4. run the following command to apply the update to your local db

careful with spaces between lines, not sure this will render the way you are thinking. I viewed the source and this number does not show up

@@ -25,7 +25,7 @@

config.set_main_option(
"sqlalchemy.url",
current_app.config.get("SQLALCHEMY_DATABASE_URI").replace("%", "%%"),
str(current_app.extensions["migrate"].db.engine.url).replace("%", "%%"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this change @mtreacy002 ? just asking because at the moment this came to the project, I thought it was kind of auto-generated code 🤔 but i am not sure

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Category: Coding Changes to code base or refactored code that doesn't fix a bug. Category: Documentation/Training Improvements or additions to documentation. Status: Needs Review PR needs an additional review or a maintainer's review. Type: Enhancement New feature or request.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Write on README how to create and run db migration script
3 participants