multi-db | Allows you to partition your large WordPress Multisite | Database library

 by   wpmudev PHP Version: 3.2.5 License: GPL-2.0

kandi X-RAY | multi-db Summary

kandi X-RAY | multi-db Summary

multi-db is a PHP library typically used in Database applications. multi-db has no bugs, it has no vulnerabilities, it has a Strong Copyleft License and it has low support. You can download it from GitHub.

Allows you to partition your large WordPress Multisite database across multiple servers for scalability.
Support
    Quality
      Security
        License
          Reuse

            kandi-support Support

              multi-db has a low active ecosystem.
              It has 80 star(s) with 63 fork(s). There are 16 watchers for this library.
              OutlinedDot
              It had no major release in the last 6 months.
              There are 6 open issues and 5 have been closed. On average issues are closed in 137 days. There are 1 open pull requests and 0 closed requests.
              It has a neutral sentiment in the developer community.
              The latest version of multi-db is 3.2.5

            kandi-Quality Quality

              multi-db has 0 bugs and 0 code smells.

            kandi-Security Security

              multi-db has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              multi-db code analysis shows 0 unresolved vulnerabilities.
              There are 0 security hotspots that need review.

            kandi-License License

              multi-db is licensed under the GPL-2.0 License. This license is Strong Copyleft.
              Strong Copyleft licenses enforce sharing, and you can use them when creating open source projects.

            kandi-Reuse Reuse

              multi-db releases are not available. You will need to build from source code and install.
              It has 998 lines of code, 18 functions and 7 files.
              It has high code complexity. Code complexity directly impacts maintainability of the code.

            Top functions reviewed by kandi - BETA

            kandi has reviewed multi-db and discovered the below as its top functions. This is intended to give you an instant insight into multi-db implemented functionality, and help decide if they suit your requirements.
            • Analyze a SQL query
            • Execute a SQL query
            • Get available servers for a specific operation
            • Sanitize query tables .
            • Connect to the database
            • Connect to a server .
            • Find a global read database
            • Get datatable data for a blog ID
            • Handle a database connection failure .
            • Get all tables .
            Get all kandi verified functions for this library.

            multi-db Key Features

            No Key Features are available at this moment for multi-db.

            multi-db Examples and Code Snippets

            No Code Snippets are available at this moment for multi-db.

            Community Discussions

            QUESTION

            Django how to create, update and keep clone objects to another database for backup purpose?
            Asked 2022-Feb-12 at 20:58

            postgresql is my primary data base. If any object create in my original database then I want it will also keep an duplicate object in my secondary database. I read Django documentation for create an clone database but didn't work. here is my code:

            #replicarouter.py

            ...

            ANSWER

            Answered 2022-Feb-12 at 20:56

            finally I find out an solution. After reading django multiple database documentation we can use multiple database but can't keep clone object in our database. Let explain little bit assume you have two model teacher and student. You can use two separate database for teacher and student but you can't use another database for keep clone objects of your teacher and student model. So here we will use django siganls for keep clone objects in our replica_database. Signals will be triggered and create clone object whenever any objects create in our model. Here is my code:

            settings.py

            Source https://stackoverflow.com/questions/71080228

            QUESTION

            Django: prevent making migrations for some models
            Asked 2021-Aug-21 at 06:10

            Django 3.2.6

            I'd like some models not to made migrations at all.

            Is it possible?

            I tried:

            1. https://docs.djangoproject.com/en/3.2/ref/models/options/#managed

            class Meta: managed = False

            2.

            ...

            ANSWER

            Answered 2021-Aug-21 at 06:10

            In you class, add following line:

            Source https://stackoverflow.com/questions/68870439

            QUESTION

            Django database routers - how do you test them, especially for migrations?
            Asked 2021-Jul-11 at 08:37

            I've read the documentation on database routers in Django 2.2. I more or less understand the concept - including keeping certain tables together - except that it seems somewhat tricky to do in practice.

            My instincts when things are complicated and interdependent is to use unit tests to gradually get my code to return expected results. Except that I don't know how to write tests in this case.

            Databases in settings: ...

            ANSWER

            Answered 2021-Jul-11 at 08:37

            The master router is simply an instance of django.db.utils.ConnectionRouter, so you can instantiate that and call its methods to perform your tests.

            You can see the various methods this class has in the source code [GitHub], below is a list of the methods that are likely useful for your testing (in fact they mostly are the same as those on the database routers):

            • db_for_read : Same as documented. Returns the database to use for reading a model
            • db_for_write : Same as documented. Returns the database to use for writing a model
            • allow_relation : Same as documented. Returns whether relation between two instances is allowed
            • allow_migrate : Same as documented. Returns whether a model / model from some app can be migrated to some db.
            • allow_migrate_model : This is just a small utility function to call allow_migrate easily.

            Here is a small snippet to get you started:

            Source https://stackoverflow.com/questions/68233451

            QUESTION

            Django migration with 2 DBs?
            Asked 2021-Jun-14 at 16:41

            I've the databases db1 and db2. The schemas of both DBs should be created with the same migration script.

            The Django docs mention DATABASE_ROUTERS and RunPython, but I didn't manage to get it working so far. The function is called, but migrations.CreateModel() has no impact when called from the function: the table is not created.

            Migration script:

            ...

            ANSWER

            Answered 2021-Jun-14 at 16:41

            migrations.CreateModel does not create a model in the database upon instantiation. It is supposed to be present in the operations list where the migrations system will then use it to create the model. Furthermore you shouldn't be writing this migration manually anyway! Just write the code for the model in models.py:

            Source https://stackoverflow.com/questions/67973673

            QUESTION

            Django: Custom router for read-replica raises OperationalError on save (with related models)
            Asked 2021-May-07 at 15:27

            I'm testing out a custom database router for a Django project to support read replicas (based on the Django docs on multiple database) and when I create model instances containing references to other models, the save method tries to use the read-replica, for some reason.

            I've registered the following router in the DATABASE_ROUTERS settings:

            ...

            ANSWER

            Answered 2021-May-07 at 14:49

            Your router only defines db_for_read. Although I don't know what exactly is happening but I assume, what happens is that _state.db of the foreign key is somehow copied to the instance you are creating causing the master router to try saving to replica. Another obvious issue you haven't considered is something like this happening:

            Source https://stackoverflow.com/questions/67423389

            QUESTION

            Why django_migrations table is created even though router does not allow migrations?
            Asked 2021-Feb-10 at 14:14

            I have 'default' and 'secondary' databases. Why, even though it is stated:

            ...

            ANSWER

            Answered 2021-Feb-10 at 14:14

            Yes this was intentional as documented

            makemigrations always creates migrations for model changes, but if allow_migrate() returns False, any migration operations for the model_name will be silently skipped

            So that would mean that only migration operations will be skipped

            Source https://stackoverflow.com/questions/66138366

            QUESTION

            Django Routers with multiples schema in database
            Asked 2021-Jan-11 at 17:29

            I have one database with multitples schemas, and I try to use routers to manage record informations. (https://www.amvtek.com/blog/posts/2014/Jun/13/accessing-multiple-postgres-schemas-from-django/)

            In my django settings:

            ...

            ANSWER

            Answered 2021-Jan-11 at 17:29

            I found the solution. In fact you need to use database parameter, like this:

            Source https://stackoverflow.com/questions/65519069

            QUESTION

            Django migrations wrongly applying
            Asked 2020-Nov-07 at 14:07
            Basic problem

            I'm working on a django project where I'm using multiple databases with a custom router. Therefore, django should know which database to use for which app.

            Now I came across some in my opinion weird behaviour and wanted to ask if anyone knew if that is the correct behaviour or not, especially because the github page doesn't seem to have an issues tracker.

            To make the point clear, I'm using an extreme example, which I nonetheless tried. For testing purposes, I set the allow_migrate function to just return False.
            I did create a custom router which overrides the allow_migrate function and I also registered it under the DATABASE_ROUTERS settings. The allow_migrate function is also called, as I checked it with some print statements.

            How I understand the router usage

            The way I understand the documentation for using multiple databases with a custom router, the allow_migration method specifies if a migration is to be applied for the current db, app_label and model_name. If it returns True, the migration is applied, if False, it is 'silently skipped' and therefore not applied.

            What I expected

            As I set the allow_migrate function to return False all the time, I expected that none of the yet unapplied migrations are applied.

            What actually happens

            The migrations are, as the documentation states, indeed 'silently skipped', but the table django_migrations is nonetheless being filled with the not yet applied migrations.

            Why that is a problem

            Therefore, if I had an actual logic in the allow_migrate function, even if the migration is correctly not applied, e.g. because the database is being tested for a specific app that should not be stored in that database, the django_migrations table of that database is being filled with wrong data.

            So, is that the wanted behaviour? Am I just using the function allow_migrate wrong and should actually be using something else?

            In case it is relevant, I'm using django version 3.1.2 and my database is a mariadb database.

            ...

            ANSWER

            Answered 2020-Nov-07 at 14:07

            I kind of figured out how the described problem is actually wanted.

            It seems like for every database that django knows of, it is writing the migrations that one created with makemigrations into the django_migrations table, even if it did not actually apply the migration. Therefore, it keeps track of which migrations are newly created each time and only considers the migrations that are not stored in the django_migrations table.

            To make it clear once again: In every case, if a migration is applied or not, it is written into the django_migrations table. If the migration is actually applied is only decided by the allow_migrate function I mentioned. There is no clue, however, if the migration actually got applied or not, except for looking into the tables that were changed in that database.

            I suggest, that django should either say so in the console or just add a field applied into the django_migrations. Maybe I'm gonna prepare a pull request for that.

            Source https://stackoverflow.com/questions/64507823

            QUESTION

            Rails 6: why is it appending a number to the db name during model testing in a multi-db app?
            Asked 2020-May-07 at 09:56

            I have the following multi-db setup in my rails 6.0.2.2 app:

            ...

            ANSWER

            Answered 2020-May-07 at 09:56

            Check parallel testing in Rails 6. https://edgeguides.rubyonrails.org/testing.html#parallel-testing. That's why rails creates multiple DBs.

            Source https://stackoverflow.com/questions/61643339

            QUESTION

            Confusion over Multiple Database Configuration
            Asked 2020-Apr-13 at 01:34

            I am trying to use multiple database where one DB is a default and the second DB is a :memory DB. From the description in the Docs (shown below), it sounds like the default routing should be fine. But it says that the objects are "sticky" to their original database. How is there an "Original" database?

            When I first started to implement this, I expected that there would be a META in the Model classes that would specify its database, but that does not seem to be the case. I see examples where people have a Mapping of Apps to DB, which would be perfect for my scenario, but then they turn around and write a Routing anyway.

            I don't want to have to always add the database to Save calls, as this would be prone to programming errors. Is there an official setting to map an App to a Database, or a Model to a Database? Or is it always required to write a Router to use multiple databases.

            ...

            ANSWER

            Answered 2020-Apr-13 at 01:32

            Yes, you need to use a router. That is Django's mechanism for deciding which database should be used for a given operation. Being able to specify this in code is much more powerful and flexible than a simple mapping.

            If your needs can be satisfied by a mapping then you can implement that functionality yourself; or perhaps there's already a third-party app for that. DATABASE_APPS_MAPPING is not a Django setting, which is why someone had to then write a router to make use of that value.

            Source https://stackoverflow.com/questions/61177173

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install multi-db

            You can download it from GitHub.
            PHP requires the Visual C runtime (CRT). The Microsoft Visual C++ Redistributable for Visual Studio 2019 is suitable for all these PHP versions, see visualstudio.microsoft.com. You MUST download the x86 CRT for PHP x86 builds and the x64 CRT for PHP x64 builds. The CRT installer supports the /quiet and /norestart command-line switches, so you can also script it.

            Support

            For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
            CLONE
          • HTTPS

            https://github.com/wpmudev/multi-db.git

          • CLI

            gh repo clone wpmudev/multi-db

          • sshUrl

            git@github.com:wpmudev/multi-db.git

          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link