Skip to main content

Utility package which runs an advanced search&replace on a mysql database.

Project description

Advanced Database Replace

Short description

A utility management library which runs an advanced search&replace action against a specified database's records (event if they are serialized).

Long description

This project aims to take search&replace to the next level by applying search&replace even to serialized records in the database. This type of project is especially effective against e.g. Wordpress databases since they may contain serialized PHP array records.

Prerequisites

  • A MySql database.
  • This project installed with:
pip install advanced_database_replace

or:

./install.sh

Usage

Replacing all occurrences on all tables

from advanced_database_replace.database_replace import DatabaseReplace
from advanced_database_replace.database_credentials import DatabaseCredentials

db_credentials = DatabaseCredentials()
db_replacer = DatabaseReplace(credentials=db_credentials)

db_replacer.replace_all('my-old-record', 'my-new-record')

Replacing all occurrences on a specific table

from advanced_database_replace.database_replace import DatabaseReplace
from advanced_database_replace.database_credentials import DatabaseCredentials

db_credentials = DatabaseCredentials()
db_replacer = DatabaseReplace(credentials=db_credentials)

db_replacer.replace('my-old-record', 'my-new-record', 'my-table')

Using custom serializer

Since (as mentioned in the description) this find&replace project handles serialized data, by default it assumes PHP serialization, however, you can provide a custom serializer.

from advanced_database_replace.database_replace import DatabaseReplace
from advanced_database_replace.database_credentials import DatabaseCredentials

class MyCustomSerializer:
    @staticmethod
    def dumps(*args, **kwargs):
        pass

    @staticmethod
    def loads(*args, **kwargs):
        pass

db_credentials = DatabaseCredentials()
db_replacer = DatabaseReplace(credentials=db_credentials, serializer=MyCustomSerializer())

db_replacer.replace_all('my-old-record', 'my-new-record')

Release history

1.0.0

Initial.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for advanced-database-replace, version 1.0.0
Filename, size File type Python version Upload date Hashes
Filename, size advanced_database_replace-1.0.0-py3-none-any.whl (17.3 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size advanced_database_replace-1.0.0.tar.gz (16.2 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page