An adapter enabling use of the schemer schema migration library with
PostgreSQL.
Examples:
extern crate postgres;
#[macro_use]
extern crate schemer;
extern crate schemer_postgres;
extern crate uuid;
use std::collections::HashSet;
use postgres::Connection;
use postgres::transaction::Transaction;
use schemer::{Migration, Migrator};
use schemer_postgres::{PostgresAdapter, PostgresAdapterError, PostgresMigration};
use uuid::Uuid;
struct MyExampleMigration;
migration!(
MyExampleMigration,
"4885e8ab-dafa-4d76-a565-2dee8b04ef60",
[],
"An example migration without dependencies.");
impl PostgresMigration for MyExampleMigration {
fn up(&self, transaction: &Transaction) -> Result<(), PostgresAdapterError> {
transaction.execute("CREATE TABLE my_example (id integer PRIMARY KEY);", &[])?;
Ok(())
}
fn down(&self, transaction: &Transaction) -> Result<(), PostgresAdapterError> {
transaction.execute("DROP TABLE my_example;", &[])?;
Ok(())
}
}
fn main() {
let conn = Connection::connect(
"postgresql://postgres@localhost/?search_path=pg_temp",
postgres::TlsMode::None).unwrap();
let adapter = PostgresAdapter::new(&conn, None);
let mut migrator = Migrator::new(adapter);
let migration = Box::new(MyExampleMigration {});
migrator.register(migration);
migrator.up(None);
}