Skip to content

Commit

Permalink
Merge branch '2.0' into feature/748-1
Browse files Browse the repository at this point in the history
  • Loading branch information
josephmancuso authored Dec 6, 2023
2 parents c315b5b + 74355a3 commit 9bed4f8
Show file tree
Hide file tree
Showing 104 changed files with 1,429 additions and 666 deletions.
2 changes: 2 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
use asdf
layout python
8 changes: 4 additions & 4 deletions .github/workflows/pythonapp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest
runs-on: ubuntu-20.04

services:
postgres:
Expand Down Expand Up @@ -35,7 +35,7 @@ jobs:
steps:
- uses: actions/checkout@v1
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
Expand All @@ -58,12 +58,12 @@ jobs:
python orm migrate --connection mysql
make test
lint:
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
name: Lint
steps:
- uses: actions/checkout@v1
- name: Set up Python 3.6
uses: actions/setup-python@v1
uses: actions/setup-python@v4
with:
python-version: 3.6
- name: Install Flake8
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pythonpublish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:

jobs:
build:
runs-on: ubuntu-latest
runs-on: ubuntu-20.04

services:
postgres:
Expand Down Expand Up @@ -37,7 +37,7 @@ jobs:
steps:
- uses: actions/checkout@v1
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
venv
.direnv
.python-version
.vscode
.pytest_*
Expand All @@ -15,4 +16,6 @@ htmlcov/*
coverage.xml
.coverage
*.log
build
build
/orm.sqlite3
/.bootstrapped-pip
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python 3.8.10
35 changes: 35 additions & 0 deletions config/test-database.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from src.masoniteorm.connections import ConnectionResolver

DATABASES = {
"default": "mysql",
"mysql": {
"host": "127.0.0.1",
"driver": "mysql",
"database": "masonite",
"user": "root",
"password": "",
"port": 3306,
"log_queries": False,
"options": {
#
}
},
"postgres": {
"host": "127.0.0.1",
"driver": "postgres",
"database": "masonite",
"user": "root",
"password": "",
"port": 5432,
"log_queries": False,
"options": {
#
}
},
"sqlite": {
"driver": "sqlite",
"database": "masonite.sqlite3",
}
}

DB = ConnectionResolver().set_connection_details(DATABASES)
29 changes: 16 additions & 13 deletions makefile
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
init:
init: .env .bootstrapped-pip

.bootstrapped-pip: requirements.txt requirements.dev
pip install -r requirements.txt -r requirements.dev
touch .bootstrapped-pip

.env:
cp .env-example .env
pip install -r requirements.txt
pip install .
# Create MySQL Database
# Create Postgres Database
test:

# Create MySQL Database
# Create Postgres Database
test: init
python -m pytest tests
ci:
make test
check: format sort lint
lint:
python -m flake8 src/masoniteorm/ --ignore=E501,F401,E203,E128,E402,E731,F821,E712,W503,F811
format:
black src/masoniteorm
black tests/
make lint
sort:
isort tests
isort src/masoniteorm
format: init
black src/masoniteorm tests/
sort: init
isort src/masoniteorm tests/
coverage:
python -m pytest --cov-report term --cov-report xml --cov=src/masoniteorm tests/
python -m coveralls
Expand Down
2 changes: 2 additions & 0 deletions orm
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ from src.masoniteorm.commands import (
MigrateCommand,
MigrateRollbackCommand,
MigrateRefreshCommand,
MigrateFreshCommand,
MakeMigrationCommand,
MakeObserverCommand,
MakeModelCommand,
Expand All @@ -25,6 +26,7 @@ application = Application("ORM Version:", 0.1)
application.add(MigrateCommand())
application.add(MigrateRollbackCommand())
application.add(MigrateRefreshCommand())
application.add(MigrateFreshCommand())
application.add(MakeMigrationCommand())
application.add(MakeModelCommand())
application.add(MakeModelDocstringCommand())
Expand Down
3 changes: 3 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[pytest]
env =
D:DB_CONFIG_PATH=config/test-database
8 changes: 8 additions & 0 deletions requirements.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
flake8==3.7.9
black
faker
pytest
pytest-cov
pytest-env
pymysql
isort
11 changes: 2 additions & 9 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
flake8==3.7.9
black==19.3b0
faker
pytest
pytest-cov
pymysql
isort
inflection==0.3.1
psycopg2-binary
python-dotenv==0.14.0
pyodbc
pendulum>=2.1,<2.2
cleo>=0.8.0,<0.9
cleo>=0.8.0,<0.9
python-dotenv==0.14.0
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# Versions should comply with PEP440. For a discussion on single-sourcing
# the version across setup.py and the project code, see
# https://packaging.python.org/en/latest/single_source_version.html
version="2.18.1",
version="2.19.2",
package_dir={"": "src"},
description="The Official Masonite ORM",
long_description=long_description,
Expand Down
4 changes: 1 addition & 3 deletions src/masoniteorm/collection/Collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def push(self, value):
self._items.append(value)

def put(self, key, value):
self[key] = value
self._items[key] = value
return self

def random(self, count=None):
Expand Down Expand Up @@ -351,7 +351,6 @@ def to_json(self, **kwargs):
return json.dumps(self.serialize(), **kwargs)

def group_by(self, key):

from itertools import groupby

self.sort(key)
Expand Down Expand Up @@ -410,7 +409,6 @@ def where(self, key, *args):
return self.__class__(attributes)

def where_in(self, key, args: list) -> "Collection":

attributes = []

for item in self._items:
Expand Down
2 changes: 2 additions & 0 deletions src/masoniteorm/commands/Entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
MigrateCommand,
MigrateRollbackCommand,
MigrateRefreshCommand,
MigrateFreshCommand,
MakeMigrationCommand,
MakeModelCommand,
MakeModelDocstringCommand,
Expand All @@ -26,6 +27,7 @@
application.add(MigrateCommand())
application.add(MigrateRollbackCommand())
application.add(MigrateRefreshCommand())
application.add(MigrateFreshCommand())
application.add(MakeMigrationCommand())
application.add(MakeModelCommand())
application.add(MakeModelDocstringCommand())
Expand Down
42 changes: 42 additions & 0 deletions src/masoniteorm/commands/MigrateFreshCommand.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from ..migrations import Migration

from .Command import Command


class MigrateFreshCommand(Command):
"""
Drops all tables and migrates them again.
migrate:fresh
{--c|connection=default : The connection you want to run migrations on}
{--d|directory=databases/migrations : The location of the migration directory}
{--f|ignore-fk=? : The connection you want to run migrations on}
{--s|seed=? : Seed database after fresh. The seeder to be ran can be provided in argument}
{--schema=? : Sets the schema to be migrated}
{--D|seed-directory=databases/seeds : The location of the seed directory if seed option is used.}
"""

def handle(self):
migration = Migration(
command_class=self,
connection=self.option("connection"),
migration_directory=self.option("directory"),
config_path=self.option("config"),
schema=self.option("schema"),
)

migration.fresh(ignore_fk=self.option("ignore-fk"))

self.line("")

if self.option("seed") == "null":
self.call(
"seed:run",
f"None --directory {self.option('seed-directory')} --connection {self.option('connection')}",
)

elif self.option("seed"):
self.call(
"seed:run",
f"{self.option('seed')} --directory {self.option('seed-directory')} --connection {self.option('connection')}",
)
5 changes: 2 additions & 3 deletions src/masoniteorm/commands/MigrateRefreshCommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class MigrateRefreshCommand(Command):
"""

def handle(self):

migration = Migration(
command_class=self,
connection=self.option("connection"),
Expand All @@ -33,11 +32,11 @@ def handle(self):
if self.option("seed") == "null":
self.call(
"seed:run",
f"None --directory {self.option('seed-directory')} --connection {self.option('connection', 'default')}",
f"None --directory {self.option('seed-directory')} --connection {self.option('connection')}",
)

elif self.option("seed"):
self.call(
"seed:run",
f"{self.option('seed')} --directory {self.option('seed-directory')} --connection {self.option('connection', 'default')}",
f"{self.option('seed')} --directory {self.option('seed-directory')} --connection {self.option('connection')}",
)
11 changes: 7 additions & 4 deletions src/masoniteorm/commands/MigrateStatusCommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,20 @@ def handle(self):
)
migration.create_table_if_not_exists()
table = self.table()
table.set_header_row(["Ran?", "Migration"])
table.set_header_row(["Ran?", "Migration", "Batch"])
migrations = []

for migration_file in migration.get_ran_migrations():
for migration_data in migration.get_ran_migrations():
migration_file = migration_data["migration_file"]
batch = migration_data["batch"]

migrations.append(
["<info>Y</info>", f"<comment>{migration_file}</comment>"]
["<info>Y</info>", f"<comment>{migration_file}</comment>", f"<info>{batch}</info>"]
)

for migration_file in migration.get_unran_migrations():
migrations.append(
["<error>N</error>", f"<comment>{migration_file}</comment>"]
["<error>N</error>", f"<comment>{migration_file}</comment>", "<info>-</info>"]
)

table.set_rows(migrations)
Expand Down
1 change: 0 additions & 1 deletion src/masoniteorm/commands/SeedRunCommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ def handle(self):
seeder_seeded = "Database Seeder"

else:

table = self.argument("table")
seeder_file = (
f"{underscore(table)}_table_seeder.{camelize(table)}TableSeeder"
Expand Down
1 change: 1 addition & 0 deletions src/masoniteorm/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from .MigrateCommand import MigrateCommand
from .MigrateRollbackCommand import MigrateRollbackCommand
from .MigrateRefreshCommand import MigrateRefreshCommand
from .MigrateFreshCommand import MigrateFreshCommand
from .MigrateResetCommand import MigrateResetCommand
from .MakeModelCommand import MakeModelCommand
from .MakeModelDocstringCommand import MakeModelDocstringCommand
Expand Down
8 changes: 6 additions & 2 deletions src/masoniteorm/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
import pydoc
import urllib.parse as urlparse

from .exceptions import ConfigurationNotFound, InvalidUrlConfiguration
from .exceptions import ConfigurationNotFound
from .exceptions import InvalidUrlConfiguration


def load_config(config_path=None):
Expand All @@ -12,8 +13,11 @@ def load_config(config_path=None):
2. else try to load from default config_path: config/database
"""
selected_config_path = (
config_path or os.getenv("DB_CONFIG_PATH", None) or "config/database"
os.getenv("DB_CONFIG_PATH", None) or config_path or "config/database"
)

os.environ["DB_CONFIG_PATH"] = selected_config_path

# format path as python module if needed
selected_config_path = (
selected_config_path.replace("/", ".").replace("\\", ".").rstrip(".py")
Expand Down
1 change: 0 additions & 1 deletion src/masoniteorm/connections/BaseConnection.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class BaseConnection:

_connection = None
_cursor = None
_dry = False
Expand Down
Loading

0 comments on commit 9bed4f8

Please sign in to comment.