Crate schemer_postgres
source · [−]Expand description
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::{Client, NoTls, 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: &mut Transaction) -> Result<(), PostgresAdapterError> {
transaction.execute("CREATE TABLE my_example (id integer PRIMARY KEY);", &[])?;
Ok(())
}
fn down(&self, transaction: &mut Transaction) -> Result<(), PostgresAdapterError> {
transaction.execute("DROP TABLE my_example;", &[])?;
Ok(())
}
}
fn main() {
let mut conn = Client::connect(
"postgresql://postgres@localhost",
NoTls).unwrap();
conn.execute("SET search_path = pg_temp", &[]).unwrap();
let adapter = PostgresAdapter::new(&mut conn, None);
let mut migrator = Migrator::new(adapter);
let migration = Box::new(MyExampleMigration {});
migrator.register(migration);
migrator.up(None);
}
Structs
Adapter between schemer and PostgreSQL.
Traits
PostgreSQL-specific trait for schema migrations.