Coder Social home page Coder Social logo

Comments (5)

dantownsend avatar dantownsend commented on July 4, 2024 1

Ah, I see - sorry for the confusion.

We have the ability to run all migrations - this should work:

piccolo migrations forwards all

I just checked and it's not in the docs - we should mention it here.

There's no option currently to make migrations for all apps. We do what you suggest and have something like:

piccolo migrations new all --auto

from piccolo.

dantownsend avatar dantownsend commented on July 4, 2024 1

@hoosnick Yeah, you're right - we just have to loop through all the apps.

I've opened a draft PR. It needs a few more tests, but hopefully that does the trick.

from piccolo.

dantownsend avatar dantownsend commented on July 4, 2024

This is the Piccolo equivalent:

piccolo migrations new my_app --auto

As mentioned in the discussion, we should reorder the docs, so this appears nearer the top of the page, as we mention manual migrations first, which is a less common use case.

from piccolo.

hoosnick avatar hoosnick commented on July 4, 2024

@dantownsend Yes I know this command, if I have a project with 7-8 apps to create automatic migration files for all apps at one? We need such a command, which itself creates migration files in the directories related to the changes in the tables in each app.

Here's how I see it:

piccolo migrations new all
Creating migrations for 'myapp-1':
    Created tables                        2
    Dropped tables                        0
    Renamed tables                        0
    Created table columns                 5
    Dropped columns                       0
    Columns added to existing tables      0
    Renamed columns                       0
    Altered columns                       0
Creating migrations for 'myapp-2':
    Created tables                        2
    Dropped tables                        0
    Renamed tables                        0
    Created table columns                 5
    Dropped columns                       0
    Columns added to existing tables      0
    Renamed columns                       0
    Altered columns                       0
Creating migrations for 'myapp-3':
    Created tables                        2
    Dropped tables                        0
    Renamed tables                        0
    Created table columns                 5
    Dropped columns                       0
    Columns added to existing tables      0
    Renamed columns                       0
    Altered columns                       0
piccolo migrations forwards all
                          SESSION_AUTH
----------------------------------------------------------------
👍 1 migration already complete
🏁 No migrations need to be run

                              USER
----------------------------------------------------------------
👍 3 migrations already complete
🏁 No migrations need to be run

                         PICCOLO_ADMIN
----------------------------------------------------------------
👍 0 migrations already complete
🏁 No migrations need to be run

                             myapp-1
----------------------------------------------------------------
👍 8 migrations already complete
⏩ 1 migration not yet run
🚀 Running 1 migration:
  - 2023-07-13T14:37:01:492084 [forwards]... running 2023-07-13T14:37:01:492084
ok! ✔️

                            myapp-2
----------------------------------------------------------------
👍 2 migrations already complete
⏩ 1 migration not yet run
🚀 Running 1 migration:
  - 2023-07-13T14:37:01:492084 [forwards]... running 2023-07-13T14:37:01:492084
ok! ✔️

                             myapp-3
----------------------------------------------------------------
👍 1 migration already complete
⏩ 1 migration not yet run
🚀 Running 1 migration:
  - 2023-07-13T14:37:01:492084 [forwards]... running 2023-07-13T14:37:01:492084
ok! ✔️

from piccolo.

hoosnick avatar hoosnick commented on July 4, 2024

When do you plan to add it?

I think if the AppConfig list of apps is returned in the method below, it's enough to go through the for loop in the new command function in the migrations app.

def get_app_config(self, app_name: str) -> AppConfig:
"""
Returns an ``AppConfig`` for the given app name.
"""
modules = self.get_app_modules()
for module in modules:
app_config = module.APP_CONFIG
if app_config.app_name == app_name:
return app_config
raise ValueError(f"No app found with name {app_name}")

async def new(
app_name: str,
auto: bool = False,
desc: str = "",
auto_input: t.Optional[str] = None,
):
"""
Creates a new migration file in the migrations folder.
:param app_name:
The app to create a migration for.
:param auto:
Auto create the migration contents.
:param desc:
A description of what the migration does, for example --desc='adding
name column'.
:param auto_input:
If provided, all prompts for user input will automatically have this
entered. For example, --auto_input='y'.
"""
print("Creating new migration ...")
engine = Finder().get_engine()
if auto and isinstance(engine, SQLiteEngine):
sys.exit("Auto migrations aren't currently supported by SQLite.")
app_config = Finder().get_app_config(app_name=app_name)
_create_migrations_folder(app_config.migrations_folder_path)
try:
await _create_new_migration(
app_config=app_config,
auto=auto,
description=desc,
auto_input=auto_input,
)
except NoChanges:
print("No changes detected - exiting.")
sys.exit(0)

from piccolo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.