Changing Database in run time and making the changes reflect in Django in run time - python

I am developing a Cloud based data analysis tool, and I am using Django(1.10) for that.
I have to add columns to the existing tables, create new tables, change data-type of columns(part of data-cleaning activity) at the run time and can't figure out a way to update/reflect those changes, in run time, in the Django model, because those changes will be required in further analysis process.
I have looked into 'inspectdb' and 'syncdb', but all of these options would require taking the portal offline and then making those changes, which I don't want.
Please can you suggest a solution or a work-around of how to achieve this.
Also, is there a way in which I can select what database I want to work from the list of databases on my MySQL server, after running Django.

Django's ORM might not be the right tool for you if you need to change your schema (or db) online - the schema is defined in python modules and loaded once when Django's web server starts.
You can still use Django's templates, forms and other libraries and write your own custom DB access layer that manipulates a DB dynamically using python.

Related

Looking for a good database plugins API

At my work, we are using different SQL and NOSQL database types (i.e postgres, mysql, sqlite, mongodb, arangodb).
As we are creating lots of packages communicating with a database to retrieve some data. Recreating the CRUD functionality (+ methods to create schema => create table/collection/db) for each package make it harder to maintain the whole pipeline while scaling up.
In order to solve this situation more easily, we decided to create a database plugins API that allows us to abstract CRUD methods so you don't care about the backend database being used anymore on the backend side. All packages that need to communicate with a database will just wrap the plugins CRUD methods and add their own package specific behaviour.
I'm pretty sure we are not the only having this kind of situation out there, so I 've been looking on the web to try to find if such a thing has already been done without finding anything interesting.
Could anyone refer me to anything that may do/try to do it?
Is there anything that already does it using Python?
Thanks

Use Django with MongoDB

I have a large mongo database with documents and i want to make Django website that is going to be a client to this mongo database but it can only filter (aggregate) and view information from database without any edit/update operations. I don't want to put other web site data (users' data, comments, other information) to mongo db.
I'm new to django framework and i wonder if it is better to connect mongodb and django using, for example, mongoengine and use two databases (one for the web site data, and the second one for external documents in mongodb) or use pymongo inside django to fetch data from external db and somehow transform it to djungo models?
Yup, you're spot on, in your case of needing two separate databases, it would be better to use mongoengine in order to use two separate databases. Check out this link. It goes over defining what database to use on a per-model basis so to say.
That most likely would work great. Basically you can query using the model the same way, regardless of the database is uses, but describe which database to use on the model itself.
Hope this helps!

Django app as database web based UI

I'm planning to develop web UI something like iSQL*Plus-oracle but, for most common databases. Just take input query from user and return result with save options,etc.
So, for connecting to external data bases, what is advisable way,
1. Using django model and raw sql or,
2. with modules outside django - sqlalchemy+mysqldb,psycopg..?
Going through django documentation my understanding is db connections has to be in settings.py and I could not add from user input. Is my understanding is true or not?
I'm new to django not to python.
An ORM (something like Django's models or sqlalchemy) is a really helpful abstraction to help map tabular data in the database to the objects its being used to model in your code. It won't help with connecting to databases provided by the user since you won't know what the schema of the database is you're connecting to, nor what you are going to receive back from a query.
With django, the database defined in settings.py is used to store information related to your app such as user credentials, migrations as well as whatever else you define in your models.py files. So definitely don't try to change that dynamically as it is being used to store the state of your application for all users.
If you need to connect to external databases and run user-supplied queries, you can do that inside a view using the appropriate database driver. So psycopg2 for postgres would be fine.

Synchronizing two databases via mappings in Python

I have a live Django 1.6 project that makes use of a postgresql database. I've currently been developing an API for the project to support a mobile app - making use of South migrations as I go along.
As a result of the of this: I have a new database structure and code-base that is quite far removed from my production database although many of the fields in the production database are still present in the new one.
So as it sits - I have the mobile app running off the new API and the website running off the old database.
How can I go about synchronizing data between the two databases while the front-end for the new website is being developed?
i.e. When a user makes use of the app and then later goes to the website, I'd like their data to be available and vice-versa.
Solutions I've tried:
I cannot use the API to update the new database because it would trigger activation emails for users that have already been activated.
I've tried to use peewee to create a synchronization script where each field in one database is mapped to a field in the other database. This has been effective for tables where the schema are similar but I've had trouble when it comes to keeping foreign key relationships in tact.

View data not created by the model class appengine python

I have data in my database added by non model class method (Say using Sqlite3) running locally
Is there any way I can view this data or add it to a model schema?
So same database, table created and populated externally, any way to access this data?
there's a variety of sqlite tools that you can use to directly access the database.
https://addons.mozilla.org/en-US/firefox/addon/sqlite-manager/
note that this will only work on the dev server, where sqlite is used to emulate the datastore.
The better option is to look at the low level datastore API. I don't know if there's online documentation, but you can look through the python code in the App Engine SDK, look for google.appengine.api.datastore, that has all the basic datastore commands.

Categories

Resources