Giter Club home page Giter Club logo

oapth's Introduction

oapth's People

Contributors

c410-f3r avatar dependabot[bot] avatar zacck avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar

Forkers

undef1nd zacck-zz

oapth's Issues

Still alive?

Hi there!
I was just wondering if the project is still alive and what is missing to do a release on crates.
I am looking to switch my current diesel migrations to something more universal and your library seems very well made.
Thanks

Meta issue for `clean` method

Description

This issue gathers all remaining missing aspects of clean and also serves as a general tutorial.

The clean method tries to clean all objects of a database, including user created schemas, but is very tricky to implement for all databases. To make life easier, the current implementation of flyway is going to be used as a development reference (hope the flyway guys don't mind).

1. Choose a database and a missing target

For example, let's pick PostgreSQL to see what flyway does and what oapth currently can do:

https://github.com/flyway/flyway/blob/e2ffad5790f484b434a761f23e431ba8e3e232f8/flyway-core/src/main/java/org/flywaydb/core/internal/database/postgresql/PostgreSQLSchema.java#L81

pub async fn clean<B>(back_end: &mut B) -> crate::Result<ArrayString<[u8; 2048]>>

By looking into both projects, it is possible to see that oapth doesn't remove sequences, so let's implement it.

2. Implementation

Let's create the function that lists all sequences (don't forget to link and credit the original flyway source):

// https://github.com/flyway/flyway/blob/master/flyway-core/src/main/java/org/flywaydb/core/internal/database/postgresql/PostgreSQLSchema.java
#[oapth_macros::dev_tools_]
#[inline]
pub async fn sequences<B>(back_end: &mut B, schema: &str) -> crate::Result<Vec<String>>
where
  B: crate::BackEnd
{
  let mut buffer = ArrayString::<[u8; 128]>::new();
  buffer.write_fmt(format_args!(
    "SELECT sequence_name AS generic_column FROM information_schema.sequences WHERE sequence_schema = '{schema}'",
    schema = schema
  ))?;
  Ok(back_end.query_string(&buffer).await?)
}

And insert the drop statement within the clean function:

for sequence in sequences(back_end, "public").await? {
  buffer.write_fmt(format_args!("DROP SEQUENCE {};", domain))?;
}

3. Testing

Since this is a specific behavior of PostgreSQL, we are going to include some code into the already existing clean_drops_all_objs test:

pub async fn clean_drops_all_objs<B>(

...

c.back_end.execute("CREATE SEQUENCE serial START 101;").await.unwrap();

...

assert_eq!(crate::fixed_sql_commands::pg::sequences(&mut c.back_end).await.unwrap().len(), 1);

...

c.clean().await.unwrap();

...

assert_eq!(crate::fixed_sql_commands::pg::sequences(&mut c.back_end).await.unwrap().len(), 0);

...

Now it is only a matter of running the test. Go to the project root directory and type ./scripts/integration-tests-pg.sh to run your shinny new test through the diesel, tokio_postgres and sqlx database bridges.

Check out https://github.com/c410-f3r/oapth/blob/master/CONTRIBUTING.md for more information.

Issues

MS-SQL

MySql

PostgreSQL

SQLite

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.