Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ jobs:
pip install -r requirements.txt
pip install -r requirements-dev.txt

- name: Install activerecord and testsuite from PyPI
- name: Install activerecord and testsuite from Git
run: |
pip install rhosocial-activerecord==1.0.0.dev22
pip install rhosocial-activerecord-testsuite==1.0.0.dev9
pip install git+https://github.com/rhosocial/python-activerecord.git@release/v1.0.0.dev23
pip install git+https://github.com/rhosocial/python-activerecord-testsuite.git@release/v1.0.0.dev10

- name: Create postgres scenario config
run: |
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,7 @@ cython_debug/
*.crt
.env*coverage*.json
htmlcov/

# Claude Code temporary files (local only)
.claude/tmp/
.claude/plans/
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
## [v1.0.0.dev10] - 2026-04-13

### Added

- Added PostgreSQL row-level lock strength support: FOR SHARE, FOR NO KEY UPDATE, and FOR KEY SHARE. These lock strengths provide finer control over row-level locking in PostgreSQL 9.0+ (KEY SHARE requires 9.3+). ([#23](https://github.com/rhosocial/python-activerecord-postgres/issues/23))
- Added enhanced mathematical functions to PostgreSQL backend, including round_, pow, power, sqrt, mod, ceil, floor, trunc, max_, min_, and avg, with proper naming to avoid conflicts with Python builtins. ([#25](https://github.com/rhosocial/python-activerecord-postgres/issues/25))
- Added comprehensive PostgreSQL function support: array (18), network address (16), UUID (8), hstore (33), and range constructors (6). ([#26](https://github.com/rhosocial/python-activerecord-postgres/issues/26))
- Add PostgreSQL constraint support protocol with EXCLUDE and NOT VALID options ([#27](https://github.com/rhosocial/python-activerecord-postgres/issues/27))



### Fixed

- Refactored SQL function generation utilities by migrating them from types/ to functions/ directory for better module responsibility separation. ([#24](https://github.com/rhosocial/python-activerecord-postgres/issues/24))


## [v1.0.0.dev9] - 2026-04-08

### Added
Expand Down
17 changes: 12 additions & 5 deletions docs/en_US/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,36 @@
* **[Advanced Indexing](postgres_specific_features/indexing.md)**: GIN, GiST, BRIN index types
* **[RETURNING Clause](postgres_specific_features/returning.md)**: INSERT/UPDATE/DELETE RETURNING support

4. **[Transaction Support](transaction_support/README.md)**
4. **[DDL Operations](ddl/README.md)**
* **[PostgreSQL DDL Overview](ddl/README.md)**: CREATE TABLE, ALTER TABLE, DROP TABLE
* **[Example Code](../examples/chapter_04_ddl/ddl.py)**: DDL example

5. **[Transaction Support](transaction_support/README.md)**
* **[Transaction Isolation Levels](transaction_support/isolation_level.md)**: READ COMMITTED, REPEATABLE READ, SERIALIZABLE
* **[Savepoint Support](transaction_support/savepoint.md)**: nested transactions
* **[DEFERRABLE Mode](transaction_support/deferrable.md)**: deferred constraint checking
* **[Deadlock Handling](transaction_support/deadlock.md)**: failure retry mechanism

5. **[Type Adapters](type_adapters/README.md)**
6. **[Type Adapters](type_adapters/README.md)**
* **[PostgreSQL to Python Type Mapping](type_adapters/mapping.md)**: type conversion rules
* **[Custom Type Adapters](type_adapters/custom.md)**: extending type support
* **[Timezone Handling](type_adapters/timezone.md)**: TIMESTAMP WITH TIME ZONE
* **[Array Type Handling](type_adapters/arrays.md)**: PostgreSQL array support

6. **[Testing](testing/README.md)**
7. **[Testing](testing/README.md)**
* **[Test Configuration](testing/configuration.md)**: test environment setup
* **[Using testsuite for Testing](testing/testsuite.md)**: test suite usage
* **[Local PostgreSQL Testing](testing/local.md)**: local database testing

7. **[Troubleshooting](troubleshooting/README.md)**
8. **[Troubleshooting](troubleshooting/README.md)**
* **[Common Connection Errors](troubleshooting/connection.md)**: connection issue diagnosis
* **[Performance Issues](troubleshooting/performance.md)**: performance bottleneck analysis
* **[SQL Standard Compliance](troubleshooting/sql_standard.md)**: strict SQL compliance handling

8. **[Scenarios](scenarios/README.md)**
9. **[Scenarios](scenarios/README.md)**
* **[Parallel Worker Processing](scenarios/parallel_workers.md)**: correct usage in multi-process/async concurrent scenarios

10. **[Worker Isolation Experiment](examples/chapter_05_worker_isolation/README.md)**
* **[Worker Connection Isolation](examples/chapter_05_worker_isolation/README.md)**: worker process isolation experiment

> 📖 **Core Library Documentation**: To learn about the complete functionality of the ActiveRecord framework, please refer to [rhosocial-activerecord documentation](https://github.com/rhosocial/python-activerecord/tree/main/docs/en_US).
77 changes: 77 additions & 0 deletions docs/en_US/ddl/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# PostgreSQL DDL Operations

The PostgreSQL backend supports the same type-safe DDL expressions as the core library, with PostgreSQL-specific extensions.

## Supported Operations

| Operation | PostgreSQL Support | Notes |
|----------|-------------------|-------|
| `CreateTableExpression` | ✅ Full | PRIMARY KEY, NOT NULL, UNIQUE, etc. |
| `DropTableExpression` | ✅ Full | IF EXISTS, CASCADE, RESTRICT |
| `AlterTableExpression` | ✅ Full | ADD/DROP COLUMN, ALTER COLUMN |
| `CreateIndexExpression` | ✅ Full | Index types (BTREE, HASH, GIN, GiST, BRIN) |
| `DropIndexExpression` | ✅ Full | |
| `CreateViewExpression` | ✅ Full | Materialized views support |
| `DropViewExpression` | ✅ Full | |

## PostgreSQL-Specific Features

### Index Types

PostgreSQL supports various index types:

```python
create_idx = CreateIndexExpression(
dialect,
index_name="idx_users_name",
table_name="users",
columns=["name"],
index_type="GIN" # GIN, GiST, BRIN, BTREE, HASH
)
```

### Partial Indexes

PostgreSQL supports partial indexes with WHERE clause:

```python
from rhosocial.activerecord.backend.expression import Column, Literal

create_idx = CreateIndexExpression(
dialect,
index_name="idx_active_users",
table_name="users",
columns=["email"],
where=Column(dialect, "status") == Literal(dialect, "active")
)
```

### Schema Support

PostgreSQL supports schemas:

```python
create_table = CreateTableExpression(
dialect,
table_name="schema_name.users",
columns=columns
)
```

## Running the Example

```bash
cd python-activerecord-postgres
source .venv3.8/bin/activate
PYTHONPATH=src python docs/examples/chapter_04_ddl/ddl.py
```

The example tests:
1. Create table with constraints
2. Create table with IF NOT EXISTS
3. Alter table - add column
4. Alter table - drop column
5. Drop table with IF EXISTS
6. Introspection to verify schema changes

> **Note**: PostgreSQL has more powerful DDL support than SQLite. For full PostgreSQL DDL capabilities, refer to [PostgreSQL 16 Documentation](https://www.postgresql.org/docs/16/sql-createtable.html).
101 changes: 101 additions & 0 deletions docs/en_US/installation_and_configuration/backend_group.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# BackendGroup and BackendManager (PostgreSQL)

This document describes how to use `BackendGroup` and `BackendManager` with the PostgreSQL backend. For detailed API documentation, refer to the [core library documentation](../../../rhosocial-activerecord/docs/en_US/connection/connection_management.md).

## Quick Example

```python
from rhosocial.activerecord.connection import BackendGroup
from rhosocial.activerecord.backend.impl.postgres import PostgresBackend, PostgresConnectionConfig
from rhosocial.activerecord.model import ActiveRecord


class User(ActiveRecord):
name: str
email: str


# Using context manager
with BackendGroup(
name="main",
models=[User],
config=PostgresConnectionConfig(
host="localhost",
port=5432,
database="myapp",
username="app",
password="secret",
),
backend_class=PostgresBackend,
) as group:
user = User(name="John", email="john@example.com")
user.save()

# Using with multiple groups via BackendManager
from rhosocial.activerecord.connection import BackendManager

manager = BackendManager()
manager.create_group(
name="main",
models=[User],
config=PostgresConnectionConfig(host="localhost", database="main_db"),
backend_class=PostgresBackend,
)
manager.create_group(
name="stats",
config=PostgresConnectionConfig(host="localhost", database="stats_db"),
backend_class=PostgresBackend,
)

main_backend = manager.get_group("main").get_backend()
stats_backend = manager.get_group("stats").get_backend()
```

## PostgreSQL-Specific Features

### SSL/TLS Configuration

```python
config = PostgresConnectionConfig(
host="localhost",
port=5432,
database="myapp",
username="app",
password="secret",
sslmode="require",
sslrootcert="/path/to/ca.pem",
sslcert="/path/to/client.pem",
sslkey="/path/to/client.key",
)
```

### Connection Pool

PostgreSQL backend supports connection pool configuration (via `psycopg` pool):

```python
config = PostgresConnectionConfig(
host="localhost",
port=5432,
database="myapp",
username="app",
password="secret",
min_pool_size=5,
max_pool_size=20,
)
```

### Search Path

Set default schema search path:

```python
config = PostgresConnectionConfig(
host="localhost",
port=5432,
database="myapp",
username="app",
password="secret",
options="-c search_path=public,extensions",
)
```
Loading
Loading