1

We are developing a b2b application with django. For each client, we launch a new virtual server machine and a database. So each client has a separate installation of our application. (We do so because by the nature of our application, one client may require high use of resources at certain times, and we do not want one client's state to affect the others)

Each of these installations are binded to a central repository. If we update the application code, when we push to the master branch, all installations detect this, pull the latest version of the code and restart the application.

If we update the database schema on the other hand, currently, we need to run migrations manually by connecting to each db instance one by one (settings.py file reads the database settings from an external file which is not in the repo, we add this file manually upon installation).

Can we automate this process? i.e. given a list of databases, is it possible to run migrations on these databases with a single command?

2 Answers 2

3

If we update the application code, when we push to the master branch, all installations detect this, pull the latest version of the code and restart the application.

I assume that you have some sort of automation to pull the codes and restart the web server. You can just add the migration to this automation process. Each of the server's settings.py would read the database details from the external file and run the migration for you.

So the flow should be something like:

  • Pull the codes
  • Migrate
  • Collect Static
  • Restart the web server
Sign up to request clarification or add additional context in comments.

1 Comment

Normally we would go with that, but in this particular case, we do not have control over the server machine, and the details of the automation process. It is a "Web App" of Microsoft's Azure. Repository integration is provided by them automatically, but such an integration for migrations is not provided. I'd like to handle this on my local machine in this case.
1

First, I'd really look (very hard) for a way to launch a script that does as masnun suggests on the client side, really hard.

Second, if that does not work, then I'd try the following:

  • Configure on your local machine all client databases in the settings variable DATABASES
  • Make sure you can connect to all the client databases, this may need some fiddling
  • Then you run the "manage.py migrate" process with the extra flag --database=mydatabase (where "mydatabase" is the handle provided in the configuration) for EACH client database

I have not tried this, but I don't see why it wouldn't work ...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.