Expand description
An adapter enabling use of the schemerz schema migration library with PostgreSQL.
§Examples:
extern crate postgres;
#[macro_use]
extern crate schemerz;
extern crate schemerz_postgres;
extern crate uuid;
use std::collections::HashSet;
use postgres::{Client, NoTls, Transaction};
use schemerz::{Migration, Migrator};
use schemerz_postgres::{PostgresAdapter, PostgresAdapterError, PostgresMigration};
use uuid::uuid;
struct MyExampleMigration;
migration!(
MyExampleMigration,
uuid!("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§
- Postgres
Adapter - Adapter between schemerz and PostgreSQL.
Traits§
- Postgres
Migration - PostgreSQL-specific trait for schema migrations.