superset icon indicating copy to clipboard operation
superset copied to clipboard

my model definition and table created don't match

Open ripoul opened this issue 8 years ago • 4 comments

Make sure these boxes are checked before submitting your issue - thank you!

  • [* ] I have checked the superset logs for python stacktraces and included it here as text if any
  • [*] I have reproduced the issue with at least the latest released version of superset
  • [*] I have checked the issue tracker for the same issue and I haven't found one similar

Superset version

0.23.0dev

Expected results

I have to had a model object in superset for personal need. I define my model, but the table created with "superset db migrate" and "superset db upgrade" do not match with my model.

Actual results

the new table do not match with my model

Steps to reproduce

add a model definition :

class StructureBudgetaire(Model, AuditMixinNullable, ImportMixin):
    #__bind_key__ = 'struct'
    __tablename__ = 'structure_budgetaire'
    numligne = Column(Integer, primary_key=True)
    imputation = Column(String(200))
    titre = Column(String(200))
    sousbudget = Column(String(100))
    regroupement = Column(String(100))
    journaux = Column(String(100))
    analytique = Column(String(100))
    cptessd = Column(String(200))
    cptessc = Column(String(200))
    cptesexclu = Column(String(200))
    type_budget = Column(String(2))
    

    export_fields = ('numligne', 'imputation', 'titre',
                     'sousbudget', 'regroupement', 'journaux', 'analytique', 'cptessd', 'cptessc', 'cptesexclu', 'type_budget')

migrate and upgrade

and here the table created with for example the first two lines i don't want to :

CREATE TABLE structure_budgetaire (
	created_on DATETIME, 
	changed_on DATETIME, 
	numligne INTEGER NOT NULL, 
	imputation VARCHAR(200), 
	titre VARCHAR(200), 
	sousbudget VARCHAR(100), 
	regroupement VARCHAR(100), 
	journaux VARCHAR(100), 
	analytique VARCHAR(100), 
	cptessd VARCHAR(200), 
	cptessc VARCHAR(200), 
	cptesexclu VARCHAR(200), 
	type_budget VARCHAR(2), 
	changed_by_fk INTEGER, 
	created_by_fk INTEGER, 
	PRIMARY KEY (numligne), 
	FOREIGN KEY(changed_by_fk) REFERENCES ab_user (id), 
	FOREIGN KEY(created_by_fk) REFERENCES ab_user (id)
);

ripoul avatar Jul 03 '18 13:07 ripoul

Has to do with the mixins (AuditMixinNullable), but analytics tables definition don't belong in the Superset code base, probably not even on your fork...

mistercrunch avatar Jul 03 '18 14:07 mistercrunch

can we use in superset_config.py :

SQLALCHEMY_BINDS = {
    'struct':'postgresql+psycopg2://insynium:XXXXXXX@localhost:5432/supersetTestBis',
}

and in new model :

__bind_key__ = 'struct'

here the docs : http://flask-sqlalchemy.pocoo.org/2.3/binds/

the bind_key cmd seems to be ignore : all the table are created in the same database. in fact when the table are created manualy and I don't migrate it works. The migration script ignore the bind_key detail

ripoul avatar Jul 05 '18 08:07 ripoul

Why don't you create another python package with its own connection and migrations instead of jamming stuff in your Superset fork?

mistercrunch avatar Jul 05 '18 14:07 mistercrunch

it can be a solution but how superset and my new flask app can share the user connected.

ripoul avatar Aug 02 '18 14:08 ripoul