maxtepkeev / architect

A set of tools which enhances ORMs written in Python with more features
Other
391 stars 57 forks source link

Alembic downgrade; single qoutes in postgresql #88

Open TheoLisin opened 1 year ago

TheoLisin commented 1 year ago

Hi, Prior to anything else, I want to thank the developers sincerely <3 Yours tool was quite beneficial to my modest educational project! Now, back to issues.

Alembic

After applying architect partitions I can't (or didnt notice how) use command alembic downgrade -1, since the previous version of my migration had no knowledge of the additional tables added by the architect tool. Tables are linked, so it's important to delete partitions before the main table. I found only 2 ways to solve this:

single quotes

I was attempting to use the string_firstchars partition in this manner

@architect.install(
    "partition",
    type="range",
    subtype="string_firstchars",
    constraint="5",
    column="name",
    db=SYNC_SQLALCHEMY_DATABASE_URL,
)
class Author(Base):
    """Author model."""

    __tablename__ = "authors"

    id = Column(Integer, primary_key=True)
    name = Column(String(length=128))

But get an exception because certain authors' names begin with single quotations (e.g. d'Artagnan)

py4j.protocol.Py4JJavaError: An error occurred while calling o54.save. : 
org.apache.spark.SparkException: 
Job aborted due to stage failure: 
Task 2 in stage 1.0 failed 1 times, most recent failure: 
Lost task 2.0 in stage 1.0 (TID 3) (192.168.199.186 executor driver): 
java.sql.BatchUpdateException: 
Batch entry 339 
INSERT INTO authors ("gid","sid","name","orgid","orgs_count","email","organisation","id","id_user") 
VALUES ('5b8695e0e1cd8e14a36f4afa',NULL,'L''Uboš Zelinka','5f71b3031c455f439fe3fd75',0,NULL,'Faculty of Informatics and Information Technologies, Institute of Informatics and Software Engineering, Slovak University of Technology in Bratislava, Bratislava 4, Slovakia 84216',1476131,1476131) 
was aborted: ERROR: syntax error at or near "ub"

I was unable to resolve this issue, so I simply uninstalled architect partitions for that table 👍🏼

Zdorovya vam i vashim blizkim, TL