Skip to content

Commit

Permalink
[New] Version 1.0.4 - Refer to changelog in README.
Browse files Browse the repository at this point in the history
  • Loading branch information
ableinc committed Jan 8, 2023
1 parent 654af0e commit 105b85a
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 42 deletions.
44 changes: 28 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
# Mongrations

![alt text](https://img.icons8.com/dusk/64/000000/database.png "Mongrations Logo")
A migrations tool for Python 3.6+. Mongrations started as a MongoDB migrations tool but has introduced MySQL & Postgres
as compatible databases for the Mongrations tool.
A database independent migration and seeding tool for python. Compatible with MySQL, PostgreSQL and MongoDB.

## Required

- Python version 3.6 or above
- pip version 20.3 or above

## Getting Started

# Getting Started
1 . Generate a migration file
```bash
mongrations create insert-into-members
Expand All @@ -12,11 +18,6 @@ mongrations create insert-into-members
autogenerated for migration file* - **contents of up() and down() are user defined**.)
```python
from mongrations import Mongrations, Database
from pydotenvs import load_env

load_env()
# This is a MongoDB example. Go to /examples directory
# for more examples

class Mongration(Database):
def __init__(self):
Expand All @@ -38,26 +39,29 @@ class Mongration(Database):
collection.delete_one({'username': 'admin'})


Mongrations(Mongration, 'sync')
Mongrations(Mongration)
```
3 . Run migrations
```bash
mongrations migrate
```

# Install
## Install

```bash
pip install --upgrade mongrations
pip install --upgrade pip
pip install mongrations
```
or install locally
```bash
git clone https://github.com/ableinc/mongrations.git
cd mongrations
python -m pip install -r requirements.txt
python setup.py install
python -m pip install .
```

# Use
## Use

Mongrations comes with a CLI Tool and an import class for a pythonic migration approach. PyMongo, PyMySQL & Psycopg2 are used under
the hood, so follow <a href="https://api.mongodb.com/python/current/tutorial.html#getting-a-collection">PyMongo</a>'s,
<a href="https://github.com/PyMySQL/PyMySQL">PyMySQL</a>'s, or <a href="https://github.com/psycopg/psycopg2">Psycopg2</a>'s documentation
Expand Down Expand Up @@ -104,16 +108,24 @@ migrations.undo()
```
Run example migration in examples/ folder

# Issues
## Issues
Please report all issues to repo.

# Notes
## Notes
You can install psycopg2 from source via setup.py; python setup.py develop. Follow prompts.
You will need root access to development machine to install this tool.

You **MUST** have write access to your file system in order to use this application.

# Changelog
## Changelog

January 2023:
- The cache system will now keep the cache file in the ```migrations/``` directory at root
- psycopg[binary,pool] will now be installed during pip installation (pip 20.3 > is required)
- Removed the default ```pydotenvs``` import from the migration file
- Time (in ms) will be appended to file names instead of UUIDs
- The library wil be getting a rewrite and released under another name. This will be the last major release to the library under this name. Note: bug fixes will still be published.

January 2022:
- Squashed bugs
- Mongrations can now run on Linux
Expand Down
4 changes: 3 additions & 1 deletion mongrations/ClassType.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from pymysql.connections import Connection
try:
from pymysql.connections import Connection
from pymongo.database import Database
from psycopg2.extensions import cursor
except ImportError:
cursor = None
Connection = None
Database = None
from os import environ

db_type = {
Expand Down
26 changes: 13 additions & 13 deletions mongrations/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,12 @@
from os import remove, makedirs, getcwd
import json
from datetime import datetime
import uuid, pkg_resources
import time, pkg_resources
from pathlib import Path
import sys, getpass


def get_filepath():
filepath = {
'darwin': Path(f'/Users/{getpass.getuser()}/.mongrations/cache.json'),
'win32': Path('C:/Users/Programs Files/.mongrations/cache.json'),
'linux': Path(f'/home/{getpass.getuser()}/.mongrations/cache.json')
}.get(sys.platform)
filepath = Path(path.join(getcwd(), "migrations", ".cache.json"))
if not path.isdir(filepath.parent):
try:
makedirs(filepath.parent)
Expand Down Expand Up @@ -92,15 +87,20 @@ def _file_system_check(self):

def new_migration(self, name: str, directory):
try:
makedirs(path.join(getcwd(), directory))
d = path.join(getcwd(), directory)
if not path.isdir(d):
makedirs()
except FileExistsError:
print('Warning: Migration name already exists. File will still be created.\n')
name = str(uuid.uuid4())[:16] + '-' + name + '.py'
uuid = str(time.time())[:str(time.time()).index('.')]
_name_reference = name
name = name + '_' + uuid + '.py'
migration_path = path.join(getcwd(), directory + '/' + name)
reference_file = open(self._reference_file, 'r', encoding='utf-8')
with open(migration_path, 'w', encoding='utf-8') as migration_file:
migration_file.write(reference_file.read())
reference_file.close()
if path.isfile(migration_path):
self.new_migration(_name_reference, directory)
with open(self._reference_file, 'r', encoding='utf-8') as reference_file:
with open(migration_path, 'w', encoding='utf-8') as migration_file:
migration_file.write(reference_file.read())
self._write_file_obj(self._get_file_object(), migration_path)
print(f'Created new migration: {path.basename(migration_path)}')

Expand Down
4 changes: 2 additions & 2 deletions mongrations/connect.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from os import environ
from pymongo import MongoClient
import motor.motor_asyncio as motor
try:
from pymongo import MongoClient
import motor.motor_asyncio as motor
import pymysql.cursors
import psycopg2
except ImportError:
Expand Down
4 changes: 0 additions & 4 deletions mongrations/data/template.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
from mongrations import Mongrations, Database
from pydotenvs import load_env

load_env()


class Mongration(Database):
def __init__(self):
Expand Down
2 changes: 1 addition & 1 deletion mongrations/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.0.3'
__version__ = '1.0.4'
17 changes: 12 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
version=__version__,
author="AbleInc - Jaylen Douglas",
author_email="douglas.jaylen@gmail.com",
description="Mongrations; a database migration tool for Python 3.6 and above.",
description="Mongrations; a database independent migration and seeding tool for python.",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/ableinc/mongrations",
Expand All @@ -35,10 +35,17 @@
[console_scripts]
mongrations=mongrations.cli:cli
''',
install_requires=['Click', 'motor', 'pydotenvs', 'pymongo', 'PyMySQL', 'requests'],
install_requires=['Click', 'motor', 'pydotenvs', 'pymongo', 'PyMySQL', 'requests', 'psycopg[binary,pool]'],
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3 :: Only",
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
"Operating System :: OS Independent"
],
)

0 comments on commit 105b85a

Please sign in to comment.