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

Feature request: add feature flag to disable adding entry to phinxlog table on snapshot generation #556

Open
1 of 3 tasks
jrbakooba opened this issue Jun 30, 2022 · 4 comments

Comments

@jrbakooba
Copy link

This is a (multiple allowed):

  • bug

  • enhancement

  • feature-discussion (RFC)

  • CakePHP Version: 3.10.4

  • Migrations plugin version: 2.4.2

  • Bake plugin version (if relevant): 1.12.0

  • Database server (MySQL, SQLite, Postgres): MySQL Community Server (GPL) 5.7.37 x86_64

  • PHP Version: 7.4.29

  • Platform / OS: Devilbox (XAMPP-like Docker container) running on macOS Big Sur 11.6.1

What you did

  • if your migration file was created with the bake tool or not - yes
  • the exact shell command you used - ./bin/cake bake migration_snapshot MySnapshot
  • the FULL content of the migration files that cause the issue - N/A just a snapshot of my database
  • a way to recreate the schema of your database - N/A for what I'm asking

Expected Behavior

I would like for the entry in the phinxlog table to not be generated, if possible. Perhaps via a CLI switch to bake (--no-phinxlog)

Actual Behavior

As specified in the docs, once the snapshot is generated a new entry is added to phinxlog and it is marked as migrated.

That's nice for most, but my workflow is to immediately move the generated migration out of the main directory to another one because it is specifically generated for the unit tests. So when I then run ./bin/cake migrations status I get ** MISSING ** next to it.

I would prefer to be able to specify not to generate the phinxlog table entry, if possible. I checked the docs and I do not see support for any such flag.

@markstory markstory added this to the 3.x (CakePHP 4) milestone Jul 5, 2022
@markstory
Copy link
Member

Migrations plugin version: 2.4.2

I saw that you had your version as 2.4.2. We're unlikely to do any additional feature work on 2.x and any additions` will be done on 3.x (cake 4) instead.

@markstory
Copy link
Member

I would prefer to be able to specify not to generate the phinxlog table entry, if possible. I checked the docs and I do not see support for any such flag.

So you're looking to create a 'phantom' migration? A migration that both exists as a file but doesn't exist in the database log of migrations that have been run? Would you also expect that this flag/option would result in the generated migration snapshot be run in the next bin/cake migrations migrate?

I also think that even with the current behavior of migration_snapshot you could also approach the solution to this problem as one that can be solved by using bin/cake migrations rollback . Doing this would revert the phinxlog to match the state you want.

@jrbakooba
Copy link
Author

jrbakooba commented Jul 5, 2022

So you're looking to create a 'phantom' migration? A migration that both exists as a file but doesn't exist in the database log of migrations that have been run?

Yes, this is exactly correct 😄 I know it sounds strange, but the reason for this is that my unit tests are configured to run this "migration" to set up the test database prior to running. I have an extremely large database, and it is easier to do it this way than to manage all my fields in my fixture files. It is very convenient for the test runner to just detect a single migration file and ensure the table structure is up-to-date.

The trouble is, once I generate this file with the bake command, then move it to the Snapshots/ directory, it still has a Phinx migration entry and it is listed as **MISSING**. But I specifically want this migration to be off by itself because it is only for the unit tests.

I saw that you had your version as 2.4.2. We're unlikely to do any additional feature work on 2.x and any additions` will be done on 3.x (cake 4) instead.

OK, thank you.

bin/cake migrations rollback

I will look into this as a solution, thanks!

@jamisonbryant
Copy link

Update: I'm now using the 3.x version of the plugin and this feature would still be a wonderful thing to have for my workflow, on several projects.

It could be as simple as a --no-phinxlog option that prevents the table from being updated or touched in any way.

Folks in the community have suggested solutions involving rollbacks and also special checks that would disable the test migration in certain scenarios, but none of those solutions meet my true base use case, which is I just want to generate a single migration file containing nothing but my schema, and then exit.

So, since the feature is still nice-to-have on the active development version (3.x), can we consider this feature request again please? 😸

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants