Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
tarsil authored Aug 7, 2024
2 parents 95d37a3 + f1a46bf commit 2f0a04c
Show file tree
Hide file tree
Showing 56 changed files with 809 additions and 334 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
- uses: "actions/setup-python@v5"
with:
python-version: "${{ matrix.python-version }}"
- uses: actions/cache@v3
- uses: actions/cache@v4
id: cache
with:
path: ${{ env.pythonLocation }}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ node_modules/
results/
site/
target/
venv

# files
**/*.so
Expand Down
20 changes: 2 additions & 18 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# See https://pre-commit.com for more information.
# See https://pre-commit.com/hooks.html for more hooks.
default_language_version:
python: python3.10
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
Expand All @@ -21,29 +19,15 @@ repos:
- --py3-plus
- --keep-runtime-typing
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.254
rev: v0.3.0
hooks:
- id: ruff
args: ["--fix", "--line-length=99"]
- repo: https://github.com/psf/black
rev: 22.8.0
rev: 24.4.1
hooks:
- id: black
args: ["--line-length=99"]
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
name: isort (python)
args: ["--project=saffier", "--line-length=99"]
- id: isort
name: isort (cython)
types: [cython]
args: ["--project=saffier", "--line-length=99"]
- id: isort
name: isort (pyi)
types: [pyi]
args: ["--project=saffier", "--line-length=99"]
ci:
autofix_commit_msg: 🎨 [pre-commit.ci] Auto format from pre-commit.com hooks
autoupdate_commit_msg: ⬆ [pre-commit.ci] pre-commit autoupdate
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@

---

## Announcement

Saffier is and always will be free and belongs to the community but due to the advancement of the [Dymmond](https://github.com/dymmond)
ecosystem, it was decided to persue the continuation of a more customisable, versatile, modular and faster tool
to maintain and grow, [Edgy](https://edgy.dymmond.com). This does not mean Saffier will be forgotten, quite the opposite but the main
efforts are focused on the open source of the ecosystem of Dymmond as there is a lot of work to carry on and the community is driven
by that.

**If you would like to continue with Saffier and also maintain it, I'm more than happy to pass it on to you as Saffier can grow in so many**
other possible ways that we can't even quantify it here.

## Motivation

Almost every project, in one way or another uses one (or many) databases. An ORM is simply an mapping
Expand All @@ -44,7 +55,7 @@ are done into a more common and familiar interface.

## Before continuing

If you are looking for something more **Pyadntic** oriented where you can take literally advantage
If you are looking for something more **Pydantic** oriented where you can take literally advantage
of everything that Pydantic can offer, then instead of continuing with Saffier, have a look at
its ***data ORM brother***, [Edgy](https://edgy.tarsild.io).

Expand Down
12 changes: 6 additions & 6 deletions docs/fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,9 @@ class MyModel(saffier.Model):

##### Parameters

* **auto_now** - A boolean indicating the `auto_now` enabled.
* **auto_now_add** - A boolean indicating the `auto_now_add` enabled.

* **auto_now** - A boolean indicating the `auto_now` enabled. Useful for auto updates.
* **auto_now_add** - A boolean indicating the `auto_now_add` enabled. This will ensure that it is
only added once.

#### DateTimeField

Expand All @@ -199,9 +199,9 @@ class MyModel(saffier.Model):

##### Parameters

* **auto_now** - A boolean indicating the `auto_now` enabled.
* **auto_now_add** - A boolean indicating the `auto_now_add` enabled.

* **auto_now** - A boolean indicating the `auto_now` enabled. Useful for auto updates.
* **auto_now_add** - A boolean indicating the `auto_now_add` enabled. This will ensure that it is
only added once.

#### DecimalField

Expand Down
89 changes: 89 additions & 0 deletions docs/migrations/migrations.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,95 @@ unique-like parameter that demanded special attention, just the application itse

This means you can plug something else like Quart, Ella or even Sanic... Your pick.

### Using the `model_apps`

Since Saffier is framework agnostic, there is no way sometimes to tell where the models are unless
you are using them somewhere and this can be annoying if you want to generate migrations and manage
them without passing the models into the `__init__.py` of a python module

The **Migrate** object allows also to pass an extra parameter called `model_apps`. This is nothing
more nothing less than the location of the file containing the models used by your same application.

There are **three ways of passing values into the model_apps**.

* Via [dictionary](#via-dictionary).
* Via [tuple](#via-tuple).
* Via [list](#via-list).

#### Example

Let us assume we have an application with the following structure.

```shell
.
└── README.md
└── .gitignore
└── myproject
├── __init__.py
├── apps
│ ├── __init__.py
│ └── accounts
│ ├── __init__.py
│ ├── tests.py
│ ├── models.py
│ └── v1
│ ├── __init__.py
│ ├── schemas.py
│ ├── urls.py
│ └── views.py
├── configs
│ ├── __init__.py
│ ├── development
│ │ ├── __init__.py
│ │ └── settings.py
│ ├── settings.py
│ └── testing
│ ├── __init__.py
│ └── settings.py
├── main.py
├── serve.py
├── utils.py
├── tests
│ ├── __init__.py
│ └── test_app.py
└── urls.py
```

As you can see, it is quite structured but let us focus specifically on `accounts/models.py`.

There is where your models for the `accounts` application will be placed. Something like this:

```python
{!> ../docs_src/migrations/accounts_models.py !}
```

Now we want to tell the **Migrate** object to make sure it knows about this.

##### Via dictionary

```python
{!> ../docs_src/migrations/via_dict.py !}
```

As you can see the `model_apps = {"accounts": "accounts.models"}` was added in a simple fashion.
Every time you add new model or any changes, it should behave as normal as before with the key difference
that **now Saffier has a way to know exactly where your models are specifically**.

##### Via tuple

```python
{!> ../docs_src/migrations/via_tuple.py !}
```

The same for the tuple. You can simply pass `("accounts.models",)` as the location for the models.

##### Via list

```python
{!> ../docs_src/migrations/via_list.py !}
```
Finally, for the `list`. You can pass `["accounts.models"]` as the location for the models.

## Generating and working with migrations

Now this is the juicy part, right? Yes but before jumping right into this, please make sure you
Expand Down
76 changes: 74 additions & 2 deletions docs/release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,78 @@ hide:

# Release Notes

## 1.4.2

### Changed

- Add integration with the newly `databasez` 0.8.5+.
- Internal refactor of the registry.

### Fixed

- CI integration.

## 1.4.1

### Added

- Support for `list` and `tuples` as a type for [model_apps](./migrations/migrations.md#using-the-model_apps).

## 1.4.0

### Added

- Support for `model_apps` inside the `Migrate` object allowing
global discovery by application. This will make sure all apps will be properly
inspected.
- Add documentation about the new [model_apps](./migrations/migrations.md#using-the-model_apps).

### Changed

- Upgrade internal requirements.

## 1.3.7

### Changed

- New lazy loading settings system making it more unique and dynamic working side by side
with `dymmond-settings`.

## 1.3.6

### Changed

- Update internal `dymmond-settings` minimum requirement.

## 1.3.5

### Changed

**BREAKING CHANGE**

Due to some internal compatibilities, Saffier is rolling back to `SAFFIER_SETTINGS_MODULE`
from `SETTINGS_MODULE`

- `SETTINGS_MODULE` was renamed to `SAFFIER_SETTINGS_MODULE`.

## 1.3.4

### Changed

- Update internal anyio dependency.

## 1.3.3

### Changed

- Upgrade internal requirements.

### Fixed

- `auto_now` and `auto_now_add` on `save()` and `update()` wasn't only updating the
field with `auto_now`.
- Extraction of the default field for `date` and `datetime`.

## 1.3.2

### Fixed
Expand All @@ -15,7 +87,7 @@ hide:

### Fixed

- Fix default for `SETTINGS_MODULE` if nothing is provided.
- Fix default for `SAFFIER_SETTINGS_MODULE` if nothing is provided.

## 1.3.0

Expand Down Expand Up @@ -47,7 +119,7 @@ SAFFIER_SETTINGS_MODULE=...
**From version 1.3.0 is**:

```python
SETTINGS_MODULE=...
SAFFIER_SETTINGS_MODULE=...
```

The rest remains as it. More information about [how to use it in the official documentation](https://settings.dymmond.com/#how-to-use-it_1).
Expand Down
11 changes: 11 additions & 0 deletions docs/saffier.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ hide:

---

## Announcement

Saffier is and always will be free and belongs to the community but due to the advancement of the [Dymmond](https://github.com/dymmond)
ecosystem, it was decided to persue the continuation of a more customisable, versatile, modular and faster tool
to maintain and grow, [Edgy](https://edgy.dymmond.com). This does not mean Saffier will be forgotten, quite the opposite but the main
efforts are focused on the open source of the ecosystem of Dymmond as there is a lot of work to carry on and the community is driven
by that.

**If you would like to continue with Saffier and also maintain it, I'm more than happy to pass it on to you as Saffier can grow in so many**
other possible ways that we can't even quantify it here.

## Motivation

Almost every project, in one way or another uses one (or many) databases. An ORM is simply an mapping
Expand Down
20 changes: 10 additions & 10 deletions docs/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ This is exactly what happened.

The way of using the settings object within a Saffier use of the ORM is via:

* **SETTINGS_MODULE** environment variable.
* **SAFFIER_SETTINGS_MODULE** environment variable.

All the settings are **[pydantic BaseSettings](https://pypi.org/project/pydantic-settings/)** objects which makes it easier to use and override
when needed.

### SETTINGS_MODULE
### SAFFIER_SETTINGS_MODULE

Saffier by default uses is looking for a `SETTINGS_MODULE` environment variable to run and
Saffier by default uses is looking for a `SAFFIER_SETTINGS_MODULE` environment variable to run and
apply the given settings to your instance.

If no `SETTINGS_MODULE` is found, Saffier then uses its own internal settings which are
If no `SAFFIER_SETTINGS_MODULE` is found, Saffier then uses its own internal settings which are
widely applied across the system.

#### Custom settings
Expand Down Expand Up @@ -88,39 +88,39 @@ Using the example [above](#custom-settings) and the location `myproject/configs/
settings should be called like this:

```shell
$ SETTINGS_MODULE=myproject.configs.settings.MyCustomSettings saffier <COMMAND>
$ SAFFIER_SETTINGS_MODULE=myproject.configs.settings.MyCustomSettings saffier <COMMAND>
```

Example:

**Starting the default shell**

```shell
$ SETTINGS_MODULE=myproject.configs.settings.MyCustomSettings saffier shell
$ SAFFIER_SETTINGS_MODULE=myproject.configs.settings.MyCustomSettings saffier shell
```

**Starting the PTPython shell**

```shell
$ SETTINGS_MODULE=myproject.configs.settings.MyCustomSettings saffier shell --kernel ptpython
$ SAFFIER_SETTINGS_MODULE=myproject.configs.settings.MyCustomSettings saffier shell --kernel ptpython
```

**Creating the migrations folder**

```shell
$ SETTINGS_MODULE=myproject.configs.settings.MyCustomSettings saffier init
$ SAFFIER_SETTINGS_MODULE=myproject.configs.settings.MyCustomSettings saffier init
```

**Generating migrations**

```shell
$ SETTINGS_MODULE=myproject.configs.settings.MyCustomSettings saffier makemigrations
$ SAFFIER_SETTINGS_MODULE=myproject.configs.settings.MyCustomSettings saffier makemigrations
```

**Appying migrations**

```shell
$ SETTINGS_MODULE=myproject.configs.settings.MyCustomSettings saffier migrate
$ SAFFIER_SETTINGS_MODULE=myproject.configs.settings.MyCustomSettings saffier migrate
```

And the list goes on and on, you get the gist. To understand which commands are available, check
Expand Down
Loading

0 comments on commit 2f0a04c

Please sign in to comment.