Skip to content

Instantly share code, notes, and snippets.

@agusmakmun
Last active April 23, 2024 09:09
Show Gist options
  • Select an option

  • Save agusmakmun/1c7245b3039bdd02e3471e83077cc4b3 to your computer and use it in GitHub Desktop.

Select an option

Save agusmakmun/1c7245b3039bdd02e3471e83077cc4b3 to your computer and use it in GitHub Desktop.

Revisions

  1. agusmakmun revised this gist Apr 23, 2024. 1 changed file with 9 additions and 0 deletions.
    9 changes: 9 additions & 0 deletions upgrade-djstripe.md
    Original file line number Diff line number Diff line change
    @@ -61,6 +61,15 @@ Check out this issue for more information: https://github.com/dj-stripe/dj-strip
    stripe>=4.0.0,<5.0.0 # https://github.com/dj-stripe/dj-stripe/issues/1842#issuecomment-1319185657
    ```


    ### Conclusion

    1. Find the closest version that compatible with your version _(for doing migration)_.
    2. Update the dependency in `requirements.txt` file and then deploy it.
    - Don't forget to run the `python manage.py migrate djstripe` command.
    3. Change your migration file to refer to the new version (e.g., from `0006_2_3` to `0008_2_5`), and then deploy it.


    ### Alternatives

    - https://stackoverflow.com/a/31122841
  2. agusmakmun revised this gist Apr 22, 2024. 1 changed file with 15 additions and 16 deletions.
    31 changes: 15 additions & 16 deletions upgrade-djstripe.md
    Original file line number Diff line number Diff line change
    @@ -1,34 +1,33 @@
    ### Background

    In this article we will share how to upgrade the dj-stripe package flawlessly and carefully.
    In this article, we will share how to upgrade the dj-stripe package flawlessly and carefully.

    As we know the dj-stripe always squash the migration files. \
    Which mean, his migration files are totally changed, and because of this will lead the migration issues.
    As we know, dj-stripe always squashes the migration files, which means its migration files are completely changed, and leading to migration issues.

    > **So, you can't immediatelly upgrade your package too far, e.g: from 2.4.0 to 2.7.0, \
    because it will cause breaking changes, especially in your database migrations.**
    > **So, you can't immediately upgrade your package too far, for example, from 2.4.0 to 2.7.0, \
    > because it will cause breaking changes, especially in your database migrations.**

    ### How to do it?

    For example, your dj-stripe version is 2.4.0 and if your migration files refering to the old version.
    For example, if your dj-stripe version is 2.4.0 and your migration files are referring to the old version.

    ![Screenshot 2024-04-22 at 12 12 31](https://gist.github.com/assets/7134451/c938722f-4d83-4295-8dfb-3858725d48d9)

    First, you need to find which version that having that old migration. For example:
    First, you need to find which version has that old migration. For example:

    1. Search the latest version that close with your package version, e.g: 2.4.0 to 2.5.0
    2. Visit this link to find it: https://github.com/dj-stripe/dj-stripe/tags
    3. Cross check the release notes.
    4. Find which dj-stripe version that still compatible with your migration file, e.g: `0006_2_3.py`
    5. Find the last migration file of latest version https://github.com/dj-stripe/dj-stripe/tree/2.5.0/djstripe/migrations (e.g: `0008_2_5.py`) (both files must be exists, if not exists mean the new version not compatible anymore with your version).
    1. Search for the latest version that is closest to your package version, for example: 2.4.0 to 2.5.0.
    2. Visit this link to find it: https://github.com/dj-stripe/dj-stripe/tags.
    3. Cross-check the release notes.
    4. Find which dj-stripe version is still compatible with your migration file, for example: `0006_2_3.py`.
    5. Find the last migration file of the latest version at https://github.com/dj-stripe/dj-stripe/tree/2.5.0/djstripe/migrations (for example: `0008_2_5.py`) (both files must exist; if not, it means the new version is no longer compatible with your version).

    | Old Migration | New Migration |
    | ------------- | ------------- |
    | ![Screenshot 2024-04-22 at 12 17 10](https://gist.github.com/assets/7134451/e85a2738-25fb-4c31-beba-52a8f5e39c14) | ![Screenshot 2024-04-22 at 12 16 36](https://gist.github.com/assets/7134451/5c78d932-a245-4cf6-8fbb-c582e31507f3) |

    6. Update your `requirements.txt` file from `dj-stripe==2.4.0` to `dj-stripe==2.5.0`
    7. Run the `manage.py migrate djstripe` command _(this command must not be fail, if fail cross-check no.1-6)_.
    7. Run the `manage.py migrate djstripe` command _(this command must not fail; if it does, cross-check steps 1-6)._

    ```console
    (env-my-project) ➜ my-project git:(development) ✗ docker-compose -f local.yml run django python manage.py migrate djstripe
    @@ -48,15 +47,15 @@ Running migrations:
    Applying djstripe.0008_2_5... OK
    ```

    8. And then after migrate it, change your migration file to use the referer of new version (e.g: from `0006_2_3` to `0008_2_5`)
    8. And then, after migrating it, change your migration file to refer to the new version (e.g., from `0006_2_3` to `0008_2_5`).

    ![Screenshot 2024-04-22 at 12 11 42](https://gist.github.com/assets/7134451/8b73bdba-7d2c-472f-a8e5-c1f8e2f544d4)

    9. Repeat the same process for higher version.


    If you have an issue with stripe version, we can try upgrade it as well in the `requirements.txt` file.
    Check this issue for more: https://github.com/dj-stripe/dj-stripe/issues/1842#issuecomment-1319185657
    If you have an issue with the Stripe version, we can also try upgrading it in the `requirements.txt` file. \
    Check out this issue for more information: https://github.com/dj-stripe/dj-stripe/issues/1842#issuecomment-1319185657.

    ```
    stripe>=4.0.0,<5.0.0 # https://github.com/dj-stripe/dj-stripe/issues/1842#issuecomment-1319185657
  3. agusmakmun revised this gist Apr 22, 2024. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion upgrade-djstripe.md
    Original file line number Diff line number Diff line change
    @@ -60,4 +60,8 @@ Check this issue for more: https://github.com/dj-stripe/dj-stripe/issues/1842#is

    ```
    stripe>=4.0.0,<5.0.0 # https://github.com/dj-stripe/dj-stripe/issues/1842#issuecomment-1319185657
    ```
    ```

    ### Alternatives

    - https://stackoverflow.com/a/31122841
  4. agusmakmun revised this gist Apr 22, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion upgrade-djstripe.md
    Original file line number Diff line number Diff line change
    @@ -21,7 +21,7 @@ First, you need to find which version that having that old migration. For exampl
    2. Visit this link to find it: https://github.com/dj-stripe/dj-stripe/tags
    3. Cross check the release notes.
    4. Find which dj-stripe version that still compatible with your migration file, e.g: `0006_2_3.py`
    5. Find the last migration file of latest version https://github.com/dj-stripe/dj-stripe/tree/2.5.0/djstripe/migrations (e.g: `0008_2_5.py`) (both files must be exist, if not exist mean the new version not yet compatible with your version).
    5. Find the last migration file of latest version https://github.com/dj-stripe/dj-stripe/tree/2.5.0/djstripe/migrations (e.g: `0008_2_5.py`) (both files must be exists, if not exists mean the new version not compatible anymore with your version).

    | Old Migration | New Migration |
    | ------------- | ------------- |
  5. agusmakmun revised this gist Apr 22, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion upgrade-djstripe.md
    Original file line number Diff line number Diff line change
    @@ -21,7 +21,7 @@ First, you need to find which version that having that old migration. For exampl
    2. Visit this link to find it: https://github.com/dj-stripe/dj-stripe/tags
    3. Cross check the release notes.
    4. Find which dj-stripe version that still compatible with your migration file, e.g: `0006_2_3.py`
    5. Find the last migration file of latest version https://github.com/dj-stripe/dj-stripe/tree/2.5.0/djstripe/migrations (e.g: `0008_2_5.py`)
    5. Find the last migration file of latest version https://github.com/dj-stripe/dj-stripe/tree/2.5.0/djstripe/migrations (e.g: `0008_2_5.py`) (both files must be exist, if not exist mean the new version not yet compatible with your version).

    | Old Migration | New Migration |
    | ------------- | ------------- |
  6. agusmakmun revised this gist Apr 22, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion upgrade-djstripe.md
    Original file line number Diff line number Diff line change
    @@ -48,7 +48,7 @@ Running migrations:
    Applying djstripe.0008_2_5... OK
    ```

    8. And change your migration file to use the referer of new version (e.g: `0006_2_3` to `0008_2_5`)
    8. And then after migrate it, change your migration file to use the referer of new version (e.g: from `0006_2_3` to `0008_2_5`)

    ![Screenshot 2024-04-22 at 12 11 42](https://gist.github.com/assets/7134451/8b73bdba-7d2c-472f-a8e5-c1f8e2f544d4)

  7. agusmakmun revised this gist Apr 22, 2024. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions upgrade-djstripe.md
    Original file line number Diff line number Diff line change
    @@ -23,9 +23,9 @@ First, you need to find which version that having that old migration. For exampl
    4. Find which dj-stripe version that still compatible with your migration file, e.g: `0006_2_3.py`
    5. Find the last migration file of latest version https://github.com/dj-stripe/dj-stripe/tree/2.5.0/djstripe/migrations (e.g: `0008_2_5.py`)

    ![Screenshot 2024-04-22 at 12 17 10](https://gist.github.com/assets/7134451/e85a2738-25fb-4c31-beba-52a8f5e39c14)

    ![Screenshot 2024-04-22 at 12 16 36](https://gist.github.com/assets/7134451/5c78d932-a245-4cf6-8fbb-c582e31507f3)
    | Old Migration | New Migration |
    | ------------- | ------------- |
    | ![Screenshot 2024-04-22 at 12 17 10](https://gist.github.com/assets/7134451/e85a2738-25fb-4c31-beba-52a8f5e39c14) | ![Screenshot 2024-04-22 at 12 16 36](https://gist.github.com/assets/7134451/5c78d932-a245-4cf6-8fbb-c582e31507f3) |

    6. Update your `requirements.txt` file from `dj-stripe==2.4.0` to `dj-stripe==2.5.0`
    7. Run the `manage.py migrate djstripe` command _(this command must not be fail, if fail cross-check no.1-6)_.
  8. agusmakmun revised this gist Apr 22, 2024. 1 changed file with 4 additions and 3 deletions.
    7 changes: 4 additions & 3 deletions upgrade-djstripe.md
    Original file line number Diff line number Diff line change
    @@ -22,14 +22,11 @@ First, you need to find which version that having that old migration. For exampl
    3. Cross check the release notes.
    4. Find which dj-stripe version that still compatible with your migration file, e.g: `0006_2_3.py`
    5. Find the last migration file of latest version https://github.com/dj-stripe/dj-stripe/tree/2.5.0/djstripe/migrations (e.g: `0008_2_5.py`)
    6. And change your migration file to use it.

    ![Screenshot 2024-04-22 at 12 17 10](https://gist.github.com/assets/7134451/e85a2738-25fb-4c31-beba-52a8f5e39c14)

    ![Screenshot 2024-04-22 at 12 16 36](https://gist.github.com/assets/7134451/5c78d932-a245-4cf6-8fbb-c582e31507f3)

    ![Screenshot 2024-04-22 at 12 11 42](https://gist.github.com/assets/7134451/8b73bdba-7d2c-472f-a8e5-c1f8e2f544d4)

    6. Update your `requirements.txt` file from `dj-stripe==2.4.0` to `dj-stripe==2.5.0`
    7. Run the `manage.py migrate djstripe` command _(this command must not be fail, if fail cross-check no.1-6)_.

    @@ -51,6 +48,10 @@ Running migrations:
    Applying djstripe.0008_2_5... OK
    ```

    8. And change your migration file to use the referer of new version (e.g: `0006_2_3` to `0008_2_5`)

    ![Screenshot 2024-04-22 at 12 11 42](https://gist.github.com/assets/7134451/8b73bdba-7d2c-472f-a8e5-c1f8e2f544d4)

    9. Repeat the same process for higher version.


  9. agusmakmun revised this gist Apr 22, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion upgrade-djstripe.md
    Original file line number Diff line number Diff line change
    @@ -31,7 +31,7 @@ First, you need to find which version that having that old migration. For exampl
    ![Screenshot 2024-04-22 at 12 11 42](https://gist.github.com/assets/7134451/8b73bdba-7d2c-472f-a8e5-c1f8e2f544d4)

    6. Update your `requirements.txt` file from `dj-stripe==2.4.0` to `dj-stripe==2.5.0`
    7. Run the `manage.py migrate djstripe` command _(this command must not be fail, if fail cross-check no.1-5)_.
    7. Run the `manage.py migrate djstripe` command _(this command must not be fail, if fail cross-check no.1-6)_.

    ```console
    (env-my-project) ➜ my-project git:(development) ✗ docker-compose -f local.yml run django python manage.py migrate djstripe
  10. agusmakmun revised this gist Apr 22, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion upgrade-djstripe.md
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@ In this article we will share how to upgrade the dj-stripe package flawlessly an
    As we know the dj-stripe always squash the migration files. \
    Which mean, his migration files are totally changed, and because of this will lead the migration issues.

    > **So, you can't immediatelly upgrade your package, e.g: from 2.4.0 to 2.7.0, \
    > **So, you can't immediatelly upgrade your package too far, e.g: from 2.4.0 to 2.7.0, \
    because it will cause breaking changes, especially in your database migrations.**


  11. agusmakmun revised this gist Apr 22, 2024. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions upgrade-djstripe.md
    Original file line number Diff line number Diff line change
    @@ -20,8 +20,9 @@ First, you need to find which version that having that old migration. For exampl
    1. Search the latest version that close with your package version, e.g: 2.4.0 to 2.5.0
    2. Visit this link to find it: https://github.com/dj-stripe/dj-stripe/tags
    3. Cross check the release notes.
    4. Find the last migration file of latest version https://github.com/dj-stripe/dj-stripe/tree/2.5.0/djstripe/migrations (e.g: `0008_2_5.py`)
    5. And change your migration file to use it.
    4. Find which dj-stripe version that still compatible with your migration file, e.g: `0006_2_3.py`
    5. Find the last migration file of latest version https://github.com/dj-stripe/dj-stripe/tree/2.5.0/djstripe/migrations (e.g: `0008_2_5.py`)
    6. And change your migration file to use it.

    ![Screenshot 2024-04-22 at 12 17 10](https://gist.github.com/assets/7134451/e85a2738-25fb-4c31-beba-52a8f5e39c14)

  12. agusmakmun revised this gist Apr 22, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion upgrade-djstripe.md
    Original file line number Diff line number Diff line change
    @@ -20,7 +20,7 @@ First, you need to find which version that having that old migration. For exampl
    1. Search the latest version that close with your package version, e.g: 2.4.0 to 2.5.0
    2. Visit this link to find it: https://github.com/dj-stripe/dj-stripe/tags
    3. Cross check the release notes.
    4. Find the last migration file of latest version https://github.com/dj-stripe/dj-stripe/tree/2.5.0/djstripe/migrations
    4. Find the last migration file of latest version https://github.com/dj-stripe/dj-stripe/tree/2.5.0/djstripe/migrations (e.g: `0008_2_5.py`)
    5. And change your migration file to use it.

    ![Screenshot 2024-04-22 at 12 17 10](https://gist.github.com/assets/7134451/e85a2738-25fb-4c31-beba-52a8f5e39c14)
  13. agusmakmun revised this gist Apr 22, 2024. 1 changed file with 8 additions and 0 deletions.
    8 changes: 8 additions & 0 deletions upgrade-djstripe.md
    Original file line number Diff line number Diff line change
    @@ -51,3 +51,11 @@ Running migrations:
    ```

    9. Repeat the same process for higher version.


    If you have an issue with stripe version, we can try upgrade it as well in the `requirements.txt` file.
    Check this issue for more: https://github.com/dj-stripe/dj-stripe/issues/1842#issuecomment-1319185657

    ```
    stripe>=4.0.0,<5.0.0 # https://github.com/dj-stripe/dj-stripe/issues/1842#issuecomment-1319185657
    ```
  14. agusmakmun revised this gist Apr 22, 2024. 1 changed file with 20 additions and 0 deletions.
    20 changes: 20 additions & 0 deletions upgrade-djstripe.md
    Original file line number Diff line number Diff line change
    @@ -31,3 +31,23 @@ First, you need to find which version that having that old migration. For exampl

    6. Update your `requirements.txt` file from `dj-stripe==2.4.0` to `dj-stripe==2.5.0`
    7. Run the `manage.py migrate djstripe` command _(this command must not be fail, if fail cross-check no.1-5)_.

    ```console
    (env-my-project) ➜ my-project git:(development) ✗ docker-compose -f local.yml run django python manage.py migrate djstripe
    [+] Creating 3/0
    ✔ Container my-project-redis-1 Running 0.0s
    ✔ Container my-project-mailhog-1 Running 0.0s
    ✔ Container my-project-postgres-1 Running 0.0s
    PostgreSQL is available
    System check identified some issues:

    WARNINGS:
    ?: (djstripe.W001) The Stripe API version has a non-default value of '2024-04-10'. Non-default versions are not explicitly supported, and may cause compatibility issues.
    HINT: Use the dj-stripe default for Stripe API version: 2020-08-27
    Operations to perform:
    Apply all migrations: djstripe
    Running migrations:
    Applying djstripe.0008_2_5... OK
    ```

    9. Repeat the same process for higher version.
  15. agusmakmun created this gist Apr 22, 2024.
    33 changes: 33 additions & 0 deletions upgrade-djstripe.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    ### Background

    In this article we will share how to upgrade the dj-stripe package flawlessly and carefully.

    As we know the dj-stripe always squash the migration files. \
    Which mean, his migration files are totally changed, and because of this will lead the migration issues.

    > **So, you can't immediatelly upgrade your package, e.g: from 2.4.0 to 2.7.0, \
    because it will cause breaking changes, especially in your database migrations.**


    ### How to do it?

    For example, your dj-stripe version is 2.4.0 and if your migration files refering to the old version.

    ![Screenshot 2024-04-22 at 12 12 31](https://gist.github.com/assets/7134451/c938722f-4d83-4295-8dfb-3858725d48d9)

    First, you need to find which version that having that old migration. For example:

    1. Search the latest version that close with your package version, e.g: 2.4.0 to 2.5.0
    2. Visit this link to find it: https://github.com/dj-stripe/dj-stripe/tags
    3. Cross check the release notes.
    4. Find the last migration file of latest version https://github.com/dj-stripe/dj-stripe/tree/2.5.0/djstripe/migrations
    5. And change your migration file to use it.

    ![Screenshot 2024-04-22 at 12 17 10](https://gist.github.com/assets/7134451/e85a2738-25fb-4c31-beba-52a8f5e39c14)

    ![Screenshot 2024-04-22 at 12 16 36](https://gist.github.com/assets/7134451/5c78d932-a245-4cf6-8fbb-c582e31507f3)

    ![Screenshot 2024-04-22 at 12 11 42](https://gist.github.com/assets/7134451/8b73bdba-7d2c-472f-a8e5-c1f8e2f544d4)

    6. Update your `requirements.txt` file from `dj-stripe==2.4.0` to `dj-stripe==2.5.0`
    7. Run the `manage.py migrate djstripe` command _(this command must not be fail, if fail cross-check no.1-5)_.