René's URL Explorer Experiment


Title: Migrations drop and identically recreate certain foreign keys · Issue #271 · googleapis/python-spanner-sqlalchemy · GitHub

Open Graph Title: Migrations drop and identically recreate certain foreign keys · Issue #271 · googleapis/python-spanner-sqlalchemy

X Title: Migrations drop and identically recreate certain foreign keys · Issue #271 · googleapis/python-spanner-sqlalchemy

Description: Hello! I'm opening a new issue, but this looks quite possibly related to issue 231. Following the release of version 1.2.2, we observe a new, strange behavior in migrations regarding a slightly tricky foreign key we use. In short, we are...

Open Graph Description: Hello! I'm opening a new issue, but this looks quite possibly related to issue 231. Following the release of version 1.2.2, we observe a new, strange behavior in migrations regarding a slightly tri...

X Description: Hello! I'm opening a new issue, but this looks quite possibly related to issue 231. Following the release of version 1.2.2, we observe a new, strange behavior in migrations regarding a slightly...

Opengraph URL: https://github.com/googleapis/python-spanner-sqlalchemy/issues/271

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Migrations drop and identically recreate certain foreign keys","articleBody":"Hello! I'm opening a new issue, but this looks quite possibly related to [issue 231](https://github.com/googleapis/python-spanner-sqlalchemy/issues/231).\r\n\r\nFollowing the release of version 1.2.2, we observe a new, strange behavior in migrations regarding a slightly tricky foreign key we use.\r\n\r\nIn short, we are linking two entities together in a table, and we want to enforce that a certain property of entities A and B match. This worked perfectly well in 1.2.1.\r\n\r\nIn 1.2.2, the keys' enforcement actually still works, but every new migration we create drops that linking table's foreign keys and recreates them identically. This does not happen only once, but in every subsequent migration.\r\n\r\nHere are the relevant package versions we use:\r\n\r\nalembic                                  1.8.1\r\ngoogle-cloud-spanner           3.22.2\r\nSQLAlchemy                           1.4.41\r\nsqlalchemy-spanner               1.2.2\r\n\r\nAnd here's a minimalist setup that recreates the problem.\r\n\r\n```\r\nfrom __future__ import annotations\r\n\r\nfrom sqlalchemy import Column, ForeignKey, ForeignKeyConstraint, PrimaryKeyConstraint, String\r\nfrom sqlalchemy.ext.declarative import declared_attr\r\nfrom sqlalchemy.orm import relationship\r\n\r\nfrom shared.database_engine import Base\r\n\r\n### Base's definition from shared.database_engine (it's pretty standard):\r\n# from sqlalchemy import MetaData, create_engine\r\n# from sqlalchemy.orm import declarative_base\r\n# engine = create_engine(shared_settings.SPANNER_URL, pool_recycle=shared_settings.SPANNER_SESSION_RECYCLE_AGE)\r\n# metadata = MetaData(bind=engine)\r\n# Base = declarative_base(bind=engine, metadata=metadata)\r\n\r\n\r\nclass EnvironmentMixin:\r\n    @declared_attr\r\n    def environment_id(self) -\u003e Column[String]:\r\n        return Column(String, ForeignKey('environment.id'), nullable=False)\r\n\r\n\r\nclass Environment(Base):\r\n    __tablename__ = 'environment'\r\n\r\n    id = Column(String, primary_key=True)\r\n\r\n\r\nclass A(Base, EnvironmentMixin):\r\n    __tablename__ = 'a'\r\n\r\n    id = Column(String, primary_key=True)\r\n\r\n\r\nclass B(Base, EnvironmentMixin):\r\n    __tablename__ = 'b'\r\n\r\n    id = Column(String, primary_key=True)\r\n\r\n\r\nclass Link(Base, EnvironmentMixin):\r\n    __tablename__ = 'link'\r\n    __table_args__ = (\r\n        # Enforce at DB-level that associated A and B must share the same Environment\r\n        PrimaryKeyConstraint('environment_id', 'a_id', 'b_id', name='pk_test'),\r\n        ForeignKeyConstraint(\r\n            ['environment_id', 'a_id'],\r\n            ['a.environment_id', 'a.id'],\r\n            name='fk_1',\r\n        ),\r\n        ForeignKeyConstraint(\r\n            ['environment_id', 'b_id'],\r\n            ['b.environment_id', 'b.id'],\r\n            name='fk_2',\r\n        ),\r\n    )\r\n\r\n    a_id = Column(String, nullable=False)\r\n    b_id = Column(String, nullable=False)\r\n\r\n    a: A = relationship('A', foreign_keys=[a_id])\r\n    b: B = relationship('B', foreign_keys=[b_id])\r\n```\r\n\r\nUsing this file, I ran `alembic revision --autogenerate` for the initial setup, then `alembic upgrade head`, then immediately another `alembic revision --autogenerate`.\r\n\t\r\nOur migrations are enclosed in an autocommit block following [this issue](https://github.com/googleapis/python-spanner-sqlalchemy/issues/229).\r\n\r\nHere's the initial generation:\r\n\r\n```\r\n\"\"\"setup\r\n\r\nRevision ID: 485161853e62\r\nRevises: \r\nCreate Date: 2022-10-14 14:46:50.269607\r\n\r\n\"\"\"\r\nfrom alembic import op\r\nimport sqlalchemy as sa\r\n\r\n\r\n# revision identifiers, used by Alembic.\r\nrevision = '485161853e62'\r\ndown_revision = None\r\nbranch_labels = None\r\ndepends_on = None\r\n\r\n\r\ndef upgrade():\r\n    with op.get_context().autocommit_block():\r\n        # ### commands auto generated by Alembic - please adjust! ###\r\n        op.create_table('environment',\r\n        sa.Column('id', sa.String(), nullable=False),\r\n        sa.PrimaryKeyConstraint('id')\r\n        )\r\n        op.create_table('a',\r\n        sa.Column('id', sa.String(), nullable=False),\r\n        sa.Column('environment_id', sa.String(), nullable=False),\r\n        sa.ForeignKeyConstraint(['environment_id'], ['environment.id'], ),\r\n        sa.PrimaryKeyConstraint('id')\r\n        )\r\n        op.create_table('b',\r\n        sa.Column('id', sa.String(), nullable=False),\r\n        sa.Column('environment_id', sa.String(), nullable=False),\r\n        sa.ForeignKeyConstraint(['environment_id'], ['environment.id'], ),\r\n        sa.PrimaryKeyConstraint('id')\r\n        )\r\n        op.create_table('link',\r\n        sa.Column('a_id', sa.String(), nullable=False),\r\n        sa.Column('b_id', sa.String(), nullable=False),\r\n        sa.Column('environment_id', sa.String(), nullable=False),\r\n        sa.ForeignKeyConstraint(['environment_id', 'a_id'], ['a.environment_id', 'a.id'], name='fk_1'),\r\n        sa.ForeignKeyConstraint(['environment_id', 'b_id'], ['b.environment_id', 'b.id'], name='fk_2'),\r\n        sa.ForeignKeyConstraint(['environment_id'], ['environment.id'], ),\r\n        sa.PrimaryKeyConstraint('environment_id', 'a_id', 'b_id', name='pk_test')\r\n        )\r\n        # ### end Alembic commands ###\r\n\r\n\r\ndef downgrade():\r\n    with op.get_context().autocommit_block():\r\n        # ### commands auto generated by Alembic - please adjust! ###\r\n        op.drop_table('link')\r\n        op.drop_table('b')\r\n        op.drop_table('a')\r\n        op.drop_table('environment')\r\n        # ### end Alembic commands ###\r\n\r\n```\r\nAnd here's every subsequent autogenerated migration:\r\n\r\n\r\n\r\n```\r\n\"\"\"no modification\r\n\r\nRevision ID: 508dda784ffa\r\nRevises: 485161853e62\r\nCreate Date: 2022-10-14 14:47:00.349500\r\n\r\n\"\"\"\r\nfrom alembic import op\r\nimport sqlalchemy as sa\r\n\r\n\r\n# revision identifiers, used by Alembic.\r\nrevision = '508dda784ffa'\r\ndown_revision = '485161853e62'\r\nbranch_labels = None\r\ndepends_on = None\r\n\r\n\r\ndef upgrade():\r\n    with op.get_context().autocommit_block():\r\n        # ### commands auto generated by Alembic - please adjust! ###\r\n        with op.batch_alter_table('link', schema=None) as batch_op:\r\n            batch_op.drop_constraint('fk_2', type_='foreignkey')\r\n            batch_op.drop_constraint('fk_1', type_='foreignkey')\r\n            batch_op.create_foreign_key('fk_2', 'b', ['environment_id', 'b_id'], ['environment_id', 'id'])\r\n            batch_op.create_foreign_key('fk_1', 'a', ['environment_id', 'a_id'], ['environment_id', 'id'])\r\n\r\n        # ### end Alembic commands ###\r\n\r\n\r\ndef downgrade():\r\n    with op.get_context().autocommit_block():\r\n        # ### commands auto generated by Alembic - please adjust! ###\r\n        with op.batch_alter_table('link', schema=None) as batch_op:\r\n            batch_op.drop_constraint('fk_1', type_='foreignkey')\r\n            batch_op.drop_constraint('fk_2', type_='foreignkey')\r\n            batch_op.create_foreign_key('fk_1', 'a', ['environment_id', 'a_id'], ['id', 'environment_id'])\r\n            batch_op.create_foreign_key('fk_2', 'b', ['environment_id', 'b_id'], ['id', 'environment_id'])\r\n\r\n        # ### end Alembic commands ###\r\n```","author":{"url":"https://github.com/louimet","@type":"Person","name":"louimet"},"datePublished":"2022-10-14T15:10:44.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/271/python-spanner-sqlalchemy/issues/271"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:aeb372a6-7f42-5cab-4c08-fac9a8416aab
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idEAE8:19F60D:C5138D:1048DB1:6A519250
html-safe-nonceb9bdad24fd2ca3b08678f9f7eced674d4e3510e2a362e943459f2b352553a1f8
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFQUU4OjE5RjYwRDpDNTEzOEQ6MTA0OERCMTo2QTUxOTI1MCIsInZpc2l0b3JfaWQiOiI2NjcxNjM2NTg1NDUxMTk3MDA4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmacf9122eb955e160b1ce9b33618bc82cbabc6c476f904cd799abd50633ba15dd86
hovercard-subject-tagissue:1409498382
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/googleapis/python-spanner-sqlalchemy/271/issue_layout
twitter:imagehttps://opengraph.githubassets.com/73c9da4327667db5a548bc3a1d070f28d9c7f441bc0b0f55fd04f4c7345912a7/googleapis/python-spanner-sqlalchemy/issues/271
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/73c9da4327667db5a548bc3a1d070f28d9c7f441bc0b0f55fd04f4c7345912a7/googleapis/python-spanner-sqlalchemy/issues/271
og:image:altHello! I'm opening a new issue, but this looks quite possibly related to issue 231. Following the release of version 1.2.2, we observe a new, strange behavior in migrations regarding a slightly tri...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamelouimet
hostnamegithub.com
expected-hostnamegithub.com
Noneb9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb
turbo-cache-controlno-preview
go-importgithub.com/googleapis/python-spanner-sqlalchemy git https://github.com/googleapis/python-spanner-sqlalchemy.git
octolytics-dimension-user_id16785467
octolytics-dimension-user_logingoogleapis
octolytics-dimension-repository_id335511641
octolytics-dimension-repository_nwogoogleapis/python-spanner-sqlalchemy
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id335511641
octolytics-dimension-repository_network_root_nwogoogleapis/python-spanner-sqlalchemy
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release7aed05249554b889eb33d002851a973eebcc7e91
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/googleapis/python-spanner-sqlalchemy/issues/271#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fgoogleapis%2Fpython-spanner-sqlalchemy%2Fissues%2F271
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/open-source/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/open-source/accelerator
GitHub Starshttps://stars.github.com
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fgoogleapis%2Fpython-spanner-sqlalchemy%2Fissues%2F271
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=googleapis%2Fpython-spanner-sqlalchemy
Reloadhttps://github.com/googleapis/python-spanner-sqlalchemy/issues/271
Reloadhttps://github.com/googleapis/python-spanner-sqlalchemy/issues/271
Reloadhttps://github.com/googleapis/python-spanner-sqlalchemy/issues/271
Please reload this pagehttps://github.com/googleapis/python-spanner-sqlalchemy/issues/271
googleapis https://github.com/googleapis
python-spanner-sqlalchemyhttps://github.com/googleapis/python-spanner-sqlalchemy
Notifications https://github.com/login?return_to=%2Fgoogleapis%2Fpython-spanner-sqlalchemy
Fork 35 https://github.com/login?return_to=%2Fgoogleapis%2Fpython-spanner-sqlalchemy
Star 53 https://github.com/login?return_to=%2Fgoogleapis%2Fpython-spanner-sqlalchemy
Code https://github.com/googleapis/python-spanner-sqlalchemy
Issues 1 https://github.com/googleapis/python-spanner-sqlalchemy/issues
Pull requests 0 https://github.com/googleapis/python-spanner-sqlalchemy/pulls
Actions https://github.com/googleapis/python-spanner-sqlalchemy/actions
Projects https://github.com/googleapis/python-spanner-sqlalchemy/projects
Security and quality 0 https://github.com/googleapis/python-spanner-sqlalchemy/security
Insights https://github.com/googleapis/python-spanner-sqlalchemy/pulse
Code https://github.com/googleapis/python-spanner-sqlalchemy
Issues https://github.com/googleapis/python-spanner-sqlalchemy/issues
Pull requests https://github.com/googleapis/python-spanner-sqlalchemy/pulls
Actions https://github.com/googleapis/python-spanner-sqlalchemy/actions
Projects https://github.com/googleapis/python-spanner-sqlalchemy/projects
Security and quality https://github.com/googleapis/python-spanner-sqlalchemy/security
Insights https://github.com/googleapis/python-spanner-sqlalchemy/pulse
#289https://github.com/googleapis/python-spanner-sqlalchemy/pull/289
Migrations drop and identically recreate certain foreign keyshttps://github.com/googleapis/python-spanner-sqlalchemy/issues/271#top
#289https://github.com/googleapis/python-spanner-sqlalchemy/pull/289
https://github.com/asthamohta
api: spannerIssues related to the googleapis/python-spanner-sqlalchemy API.https://github.com/googleapis/python-spanner-sqlalchemy/issues?q=state%3Aopen%20label%3A%22api%3A%20spanner%22
priority: p2Moderately-important priority. Fix may not be included in next release.https://github.com/googleapis/python-spanner-sqlalchemy/issues?q=state%3Aopen%20label%3A%22priority%3A%20p2%22
type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.https://github.com/googleapis/python-spanner-sqlalchemy/issues?q=state%3Aopen%20label%3A%22type%3A%20bug%22
https://github.com/louimet
louimethttps://github.com/louimet
on Oct 14, 2022https://github.com/googleapis/python-spanner-sqlalchemy/issues/271#issue-1409498382
issue 231https://github.com/googleapis/python-spanner-sqlalchemy/issues/231
this issuehttps://github.com/googleapis/python-spanner-sqlalchemy/issues/229
asthamohtahttps://github.com/asthamohta
api: spannerIssues related to the googleapis/python-spanner-sqlalchemy API.https://github.com/googleapis/python-spanner-sqlalchemy/issues?q=state%3Aopen%20label%3A%22api%3A%20spanner%22
priority: p2Moderately-important priority. Fix may not be included in next release.https://github.com/googleapis/python-spanner-sqlalchemy/issues?q=state%3Aopen%20label%3A%22priority%3A%20p2%22
type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.https://github.com/googleapis/python-spanner-sqlalchemy/issues?q=state%3Aopen%20label%3A%22type%3A%20bug%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.