Automate DB Schema Migrations - CircleCI/Sequelize/GCP - google-cloud-platform

I currently am working on an Application with a MySQL back-end hosted on GCP. Code is Node.js and we use CircleCI and Sequelize. Right now after deploying my scripts, if I had any schema changes, I would go in to the database and manually add those fields with sql scripts. We create migrations in our code and want to add those new field programmatically. I need to go in the container root and manually run the npx sequelize db:migrate. Is there a way to automate that?
For background info, I come from the database side not developer side, so please be gentle if my question seems to have an obvious answer.

Related

how to do makemigrations/migrate in gnadi(python/postgresql web hebergement)

I am a python developer and new to GANDI (python/PostgreSQL web hosting). There is no document to migrate databases to their server. they have their document to deploy a Project Django but not very clear there are a lot of things missing. After taking a lot of time on the internet, I managed to deploy a Django project in their server. The site works smoothly with an SQLite database. Now I would like to make a Django Project with PostgreSQL. I have an emergency console, but I would like to work locally and then I would like to migrate the DBs to their phpPGadmin server. I just need your help to do makemigrations/migrate to thier PostgreSQL(PhpPGadmin) server. Thanks in advance.

How do I prevent my Django Database from being overwritten

Currently I have a Django application running on my personal website from PythonAnywhere.com. When I make updates to the site I login to PythonAnywhere and git pull to update my application. When I do this the data that was entered through the website since the last update gets lost from the database when I update. What can I do to overcome this?
I am currently using the SqlLite version that comes preinstalled with the Django App. This likely could be part of the issue but need some help understanding how to overcome it.
I presume that your Django project is connecting to the SQLite database that gets generated when you create a new project and you are pushing that database in your deployment. That database won't be suitable for production and won't retain your changes, you instead need to setup a database that your application can connect to.
Here is some information on PythonAnywhere about databases:
https://help.pythonanywhere.com/pages/KindsOfDatabases/
And the Django documentation:
https://docs.djangoproject.com/en/4.0/ref/databases/

When deploying updated Django code on server, the database resets

I have built an app which uses Django as a Rest API (Django rest framework). After having deployed the code on digital ocean using production grade services, everything works well. The postgresql database populates itself correctly . There is no reset of the server like on Heroku.
Except, if I change a file and push the change through gitlab(Digital ocean picks up the change and automatically deploys the updated version of the server), the database resets to its original state. I would like the server to stay as.
I have removed all migration files before pushing updates, but to no avail. I imagine it has to be something rather trivial but I can't find it.
The database is hosted also by digital ocean. I havent done any configuration. Wouldn't it be managed automatically as DO deploys the code on its servers?
I figured out what went wrong. Using the sqlite db while developping is one thing, but assuming when deploying your django app on a service provider that it will handle the whole db management is a 1000 steps too far.
Logically, whenever I pushed a new update to the server, the db would reset using the sqlite local db file of the project.
So I created a specific db on digital ocean, change the database config on the settings file of my django project to connect to it. Making the project use the external db. then I Just had to migrate project db structure to the external db.
And Voila. problem resolved

Mass Deploy same code to Heroku individual accounts

I want to set a business model where I Mass deploy same code base(Python Django with Postgres) to my customers heroku accounts .
(I want customers to manage their own accounts and for me to stay only as software provider.However customers should get a SaaS experience without me actually having to take care of multitenant details.Also customers will be able to freeze at any time and get out of the upgrade process or to switch to custom code)
So customer will purchase my software and setup the heroku account . I will get credentials from customer and add it to my deployment process and the code will be deployed each time to all the accounts for bugs fixes and for new versions.
Do you think it is possible to achieve with Heroku?
Yes, it is possible and actually it is really easy to do IHMO.
The simplest method would be to just get credentials for each account and do git push. But a better way is to use Heroku api. You can first deploy new version to your own app which will give you a compiled slug that you can then deploy to other apps. The benefit is that you will only have to run build phase once.
Take a look at Heroku Platform API, mainly at slug and release sections. You can use slug info to get url for compiled slug, slug create to upload compiled slug into your client app and release create to deploy it.
Also look into Release phase, because you need a way to run migrations for each client when you deploy.

Set up an existing Django app on another server

This must, must, must be a duplicate but I can't find the answer either here or on Google.
I have an existing Django app and I want to deploy it on another server.
What are the steps I need to go through to get it running elsewhere, in words of one syllable?
At a minimum, presumably:
create a project on the new server
copy over all my app's files into that project
edit localsettings.py or equivalent with local database settings etc
run python manage.py syncdb to create my database
load fixtures
run tests
Is that it? Are there any unofficial or official instructions for copying an app elsewhere?
Thanks.
The most basic, easy way to do it is:
Set up the server environment so that it matches the current environment as closely as possible. The most important thing is that you're using the same version of Django (obviously). You can run a different database, but it makes porting from the old server to the new server a little more involved. Otherwise, you will just have to adjust your settings to match the new server, if they can't be duplicated (ie, user names, etc).
Copy over your code
Dump your old database structure and data into the new database
Running startproject isn't strictly necessary. Your web server just needs to be configured correctly, to run django with the appropriate settings.py file -- and Django takes it from there.