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

Database schema generation doesn't create relations #21

Closed
MrJico opened this issue Dec 24, 2022 · 4 comments · Fixed by #158
Closed

Database schema generation doesn't create relations #21

MrJico opened this issue Dec 24, 2022 · 4 comments · Fixed by #158
Assignees
Labels
help wanted Extra attention is needed

Comments

@MrJico
Copy link

MrJico commented Dec 24, 2022

First, I would like to thank you for this beautifull 😍project😍.

so i oppened this issue becuase i have tested this crate on two diffrent setups and both with backends(sqllite, pg). but the generated sql code for the relations is ether completly broken or there is something wrong with my setup.

basicly i copy pasted the getting started page and made the migrations. which in theory should generate all the necessary sql code for the relation ships. but it does not.

here is an example of the sql output: ⬇️

CREATE TABLE Post (
id SERIAL NOT NULL PRIMARY KEY,
title TEXT NOT NULL,
body TEXT NOT NULL,
published BOOLEAN NOT NULL,
blog BIGINT NOT NULL,
byline TEXT 
);
CREATE TABLE Tag (
tag TEXT NOT NULL PRIMARY KEY
);
CREATE TABLE Blog (
id BIGSERIAL NOT NULL PRIMARY KEY,
name TEXT NOT NULL
);
CREATE TABLE Post_tags_Many (
owner INTEGER NOT NULL,
has TEXT NOT NULL
);
CREATE TABLE IF NOT EXISTS butane_migrations (
name TEXT NOT NULL PRIMARY KEY
);

and here in this image visualized with dbeaver:
image

yet there are not relations(foreign keys, reffrences) generated for the tables.

here an example of what the generated sql code should be: ⬇️

CREATE TABLE Blog (
    id BIGSERIAL NOT NULL PRIMARY KEY,
    name TEXT NOT NULL
);

CREATE TABLE Post (
    id SERIAL NOT NULL PRIMARY KEY,
    title TEXT NOT NULL,
    body TEXT NOT NULL,
    published BOOLEAN NOT NULL,
    blog INTEGER REFERENCES Blog(id),
    byline TEXT
);

CREATE TABLE TAG (
    tag TEXT NOT NULL PRIMARY KEY
);

CREATE TABLE Post_tags_Many (
    owner SERIAL REFERENCES Post(id),
    has TEXT REFERENCES Tag(tag),
    PRIMARY KEY (owner, has)
);


CREATE TABLE IF NOT EXISTS butane_migrations (
name TEXT NOT NULL PRIMARY KEY
);

and in this image visualized with dbeaver:

image

please keep in mind that in the example above i have not included any constraints or onupdate and ondelete and they are not generated ether.

P.S: for the example out put above, butane is version 0.5.0 and features default and pg are enabled.

@MrJico
Copy link
Author

MrJico commented Dec 24, 2022

Note : foreign key constraints in db, cascade setting are planned in the roadmap found here roadmap

@MrJico MrJico closed this as not planned Won't fix, can't repro, duplicate, stale Dec 24, 2022
@MrJico MrJico reopened this Dec 24, 2022
@Electron100
Copy link
Owner

Thanks for filing. I'm going to edit the title to be more specific about what exactly doesn't get generated.

@Electron100 Electron100 changed the title Database schema generation seems to be broken Database schema generation doesn't create foreign key constraints Dec 25, 2022
@MrJico
Copy link
Author

MrJico commented Dec 27, 2022

I think Database schema generation doesn't create relations would be a better name for the issue

@jayvdb jayvdb added the help wanted Extra attention is needed label Jun 1, 2023
@jayvdb jayvdb self-assigned this Oct 31, 2023
@Electron100 Electron100 changed the title Database schema generation doesn't create foreign key constraints Database schema generation doesn't create relations Nov 2, 2023
@jayvdb
Copy link
Collaborator

jayvdb commented Nov 13, 2023

See #166 for the next part of this - cascading the delete.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants