-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support to schema editor for moving tables between schemas
- Loading branch information
Showing
2 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import pytest | ||
|
||
from django.db import connection, models | ||
|
||
from psqlextra.backend.schema import PostgresSchemaEditor | ||
|
||
from .fake_model import get_fake_model | ||
|
||
|
||
@pytest.fixture | ||
def fake_model(): | ||
return get_fake_model( | ||
{ | ||
"text": models.TextField(), | ||
} | ||
) | ||
|
||
|
||
def test_schema_editor_alter_table_schema(fake_model): | ||
obj = fake_model.objects.create(text="hello") | ||
|
||
with connection.cursor() as cursor: | ||
cursor.execute("CREATE SCHEMA target") | ||
|
||
schema_editor = PostgresSchemaEditor(connection) | ||
schema_editor.alter_table_schema(fake_model._meta.db_table, "target") | ||
|
||
with connection.cursor() as cursor: | ||
cursor.execute(f"SELECT * FROM target.{fake_model._meta.db_table}") | ||
assert cursor.fetchall() == [(obj.id, obj.text)] | ||
|
||
|
||
def test_schema_editor_alter_model_schema(fake_model): | ||
obj = fake_model.objects.create(text="hello") | ||
|
||
with connection.cursor() as cursor: | ||
cursor.execute("CREATE SCHEMA target") | ||
|
||
schema_editor = PostgresSchemaEditor(connection) | ||
schema_editor.alter_model_schema(fake_model, "target") | ||
|
||
with connection.cursor() as cursor: | ||
cursor.execute(f"SELECT * FROM target.{fake_model._meta.db_table}") | ||
assert cursor.fetchall() == [(obj.id, obj.text)] |