Coder Social home page Coder Social logo

Comments (3)

agronholm avatar agronholm commented on June 12, 2024

Original comment by Alex Grönholm (Bitbucket: agronholm, GitHub: agronholm):


Fixed check constraint handling with alternate schemas (fixes #3)

from sqlacodegen.

agronholm avatar agronholm commented on June 12, 2024

Original comment by YKdvd NA (Bitbucket: YKdvd, GitHub: YKdvd):


It doesn't seem to be the cross-schema bit as such, but something about (at least) an ENUM column in the FK target, even though that target is okay by itself. Here's a test case (the CREATE SCHEMA commands aren't complete):

#!SQL

CREATE SCHEMA IF NOT EXISTS TParent...
CREATE SCHEMA IF NOT EXISTS TChild...

CREATE TABLE `TParent`.`BadTarget` (
	`id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
	`userGroup` enum('Guest','Administrator','Modeler','LeadModeler','Layout','LeadLayout','Layout / Animator','Layout / LeadAnimator','Animator','LeadAnimator','Lighter','LeadLighter','LeadLighter / Compositor','LeadLighter / Compositor / Director','Compositor','Lighter / Compositor','LeadCompositor','LeadCompositor / Layout / Animator','Director','TechnicalDirector','TechnicalDirector / Lighter','TechnicalDirector / Lighter / Compositor') NOT NULL DEFAULT 'Guest',
	PRIMARY KEY (`id`)
) ENGINE=`InnoDB` AUTO_INCREMENT=1 DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ROW_FORMAT=COMPACT COMMENT='' CHECKSUM=0 DELAY_KEY_WRITE=0;

CREATE TABLE `TParent`.`GoodTarget` (
	`id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
	`dummy` varchar(255) DEFAULT NULL,
	PRIMARY KEY (`id`)
) ENGINE=`InnoDB` AUTO_INCREMENT=1 DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ROW_FORMAT=COMPACT COMMENT='' CHECKSUM=0 DELAY_KEY_WRITE=0;

CREATE TABLE `TChild`.`BadSource` (
	`id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
	`fkSource` int(11) UNSIGNED DEFAULT NULL,
	PRIMARY KEY (`id`),
	CONSTRAINT `fk_BadSource_BadTarget` FOREIGN KEY (`fkSource`) REFERENCES `TParent`.`BadTarget` (`id`)  ON UPDATE CASCADE,
	INDEX `idx_BadSource_fkSource` USING BTREE (fkSource)
) ENGINE=`InnoDB` AUTO_INCREMENT=1 DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ROW_FORMAT=COMPACT COMMENT='' CHECKSUM=0 DELAY_KEY_WRITE=0;

CREATE TABLE `TChild`.`GoodSource` (
	`id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
	`fkSource` int(10) UNSIGNED DEFAULT NULL,
	PRIMARY KEY (`id`),
	CONSTRAINT `fk_GoodSource_Goodarget` FOREIGN KEY (`fkSource`) REFERENCES `TParent`.`GoodTarget` (`id`)  ON UPDATE CASCADE,
	INDEX `idx_GoodSource_fkSource` USING BTREE (fkSource)
) ENGINE=`InnoDB` AUTO_INCREMENT=1 DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ROW_FORMAT=COMPACT COMMENT='' CHECKSUM=0 DELAY_KEY_WRITE=0;

The first run below works okay, and dumps out the Parent tables. The second one works, constraining a TChild table to a TParent table (that has no ENUM). The third one fails, doing the same sort of constraint but to a target table that does have an ENUM. I don't know if it is the length of the ENUM, or just its existence, but it may be a simple thing; I won't have time to dig into your code for awhile.

#!bash

sqlacodegen mysql://dbUser:dbPassword@dbHost/TParent
sqlacodegen  --tables GoodSource mysql://dbUser:dbPassword@dbHost/TChild
sqlacodegen  --tables BadSource mysql://dbUser:dbPassword@dbHost/TChild

from sqlacodegen.

agronholm avatar agronholm commented on June 12, 2024

Original comment by Alex Grönholm (Bitbucket: agronholm, GitHub: agronholm):


SQLACodegen does not currently handle alternate schemas very well. I'll try to improve on this in the next release.

The test case would still be appreciated.

from sqlacodegen.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.