GithubHelp home page GithubHelp logo

tvallotton / models Goto Github PK

View Code? Open in Web Editor NEW
50.0 50.0 3.0 1.33 MB

A tool for automated migrations for PostgreSQL, SQLite and MySQL.

License: Apache License 2.0

Rust 100.00%
database database-migrations migrations rust sql sqlite

models's Introduction

Hello folks, this is my github account. I'm a narcissist so here are my user profile stats:

Tomas' GitHub stats

Top Langs

models's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

models's Issues

Getters for foreign keys and primary keys

Add support for getters for forein keys, with the following API:

#[derive(Model)]
struct Post {
    #[primary_key]
    id: i32, 
    #[foreign_key(User.id, on_delete="cascade")]
    author: i32
}

let post: Post =  Post::from_key(&mut conn, &id).await?;

let user: User = post.author(&mut conn).await?;

Error when using `sqlx migrate generate` on existing project

I already had a code base with handwritten (up and down) migrations. I changed my Rust struct and annotated it properly. For some reason I get the following error:

$ sqlx migrate generate
    Finished dev [unoptimized + debuginfo] target(s) in 16.92s
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Error("expected value", line: 1, column: 33)', /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/sqlx-models-cli-0.1.1/src/generate.rs:74:43
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

I tried to reproduce it inside a clean environment but that failed. In a new, clean project everything works fine. Sadly I can't link you the code.

False positive dependecy cycles

False positive errors are triggered when checking for dependency cycles if one of the dependencies is not a model. This could be fixed either by adjusting the error message of by changing the mechanism to allow this kind of behavior. This kind of permissiveness could be desirable when the structure belongs to another crate. Example:

struct A {
   id: i32, 
}

#[derive(Models)]
struct B {
   #[foreign_key(A.id)]
   a: i32
}

Moves with constraints cause conflicts

constraint names are global, so they should be dropped before a move in PostgreSQL and MySQL, as they otherwise conflict with constraints on the tempopary table.

Postgresql serial type

in postgresql there is a handy serial type would be very convenient to mark some fields (e.g. id) to have this type instead of the regular i32 -> integer conversion or in general more power to choose types. Is there any other way to have auto inc ids?

Supported Databases

What databases are currently supported? I was about to play around with it and was wondering if it currently is even possible to create migrations other than sqlite that are supported by sqlx right now. I see some occurrences of postgresql in the code and dialect sections but i don't really now how to navigate the code yet to answer that myself. It is unfortunately not mentioned in the readme etc. but some places in the code made it look like it can determine the database from the connection string DATABASE_URL=sqlite:// ... DATABASE_URL=postgres:// but it looks like it is only generating sqlite compatible migrations atm.

diesel compatibility

could be awesome to be able to use this crate with diesel.
The output files should be under
./migrations/migrationId/up.sql
./migrations/migrationId/down.sql

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.