Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uuids #115

Merged
merged 2 commits into from
Jul 21, 2023
Merged

uuids #115

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
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
- name: Create src database
shell: bash
run: |
PGPASSWORD=password psql --host=localhost --username=postgres --file=tests/examples/src.dump
PGPASSWORD=password psql --host=localhost --username=postgres --set="ON_ERROR_STOP=1" --file=tests/examples/src.dump
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this do?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It errors if there are errors. I manually edited src.dump and was getting unexpected results. Turns out that, by default, psql will happily ignore lines that error and continue unfazed.

- name: Run Unit Tests
shell: bash
run: |
Expand Down
2 changes: 2 additions & 0 deletions sqlsynthgen/make.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from mimesis.providers.base import BaseProvider
from sqlacodegen.generators import DeclarativeGenerator
from sqlalchemy import MetaData, UniqueConstraint, text
from sqlalchemy.dialects import postgresql
from sqlalchemy.sql import sqltypes

from sqlsynthgen import providers
Expand Down Expand Up @@ -220,6 +221,7 @@ def _get_provider_for_column(column: Any) -> Tuple[List[str], str, List[str]]:
(sqltypes.DateTime, False): "generic.datetime.datetime",
(sqltypes.Numeric, False): "generic.numeric.float_number",
(sqltypes.LargeBinary, False): "generic.bytes_provider.bytes",
(postgresql.UUID, False): "generic.cryptographic.uuid",
(sqltypes.String, False): "generic.text.color",
(sqltypes.String, True): "generic.person.password",
}
Expand Down
10 changes: 10 additions & 0 deletions tests/examples/src.dump
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,16 @@ CREATE TABLE public.unique_constraint_test2 (

ALTER TABLE public.unique_constraint_test2 OWNER TO postgres;

--
-- Name: data_type_test; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.data_type_test (
myuuid UUID NOT NULL
);

ALTER TABLE public.data_type_test OWNER TO postgres;

--
-- Data for Name: concept; Type: TABLE DATA; Schema: public; Owner: postgres
--
Expand Down
12 changes: 12 additions & 0 deletions tests/test_make.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from pydantic.tools import parse_obj_as
from sqlalchemy import BigInteger, Column, String
from sqlalchemy.dialects.mysql.types import INTEGER
from sqlalchemy.dialects.postgresql import UUID

from sqlsynthgen.make import (
_get_provider_for_column,
Expand Down Expand Up @@ -174,6 +175,17 @@ def test_get_provider_for_column(self) -> None:
["100"],
)

# UUID
(
_,
generator_function,
__,
) = _get_provider_for_column(Column("myuuid", UUID))
self.assertEqual(
generator_function,
"generic.cryptographic.uuid",
)


class TestMakeTables(SSGTestCase):
"""Test the make_tables function."""
Expand Down