Versioned.Migration (Versioned v0.3.1) View Source
Allows creating tables for versioned schemas.
Example
defmodule MyApp.Repo.Migrations.CreateCar do
use Versioned.Migration
def change do
create_versioned_table(:cars) do
add :name, :string
end
end
end
Link to this section Summary
Functions
Add a new column to both the main table and the versions table.
Create a table whose data is versioned by also creating a secondary table with the immutable, append-only history.
Modify orig_field
column in table table_name
and its versioned
counterpart.
Removes a column from a table and its versioned counterpart.
Rename orig_field
column in table table_name
to a new name.
Renames a table table and its versioned counterpart.
Link to this section Functions
Add a new column to both the main table and the versions table.
Create a table whose data is versioned by also creating a secondary table with the immutable, append-only history.
modify_versioned_column(table_name, column, type, opts \\ [])
View Source (macro)Modify orig_field
column in table table_name
and its versioned
counterpart.
Example
defmodule MyApp.Repo.Migrations.RenameFooToBar do
use Versioned.Migration
def change do
modify_versioned_column("my_table", :foo, :text, null: true)
end
end
Removes a column from a table and its versioned counterpart.
Example
defmodule MyApp.Repo.Migrations.RemoveFooToBar do
use Versioned.Migration
def change do
remove_versioned_column("my_table", :foo)
end
end
Rename orig_field
column in table table_name
to a new name.
Note that this is indeed changing the field names as well in the complimenting and generally immutable "versions" table.
Example
defmodule MyApp.Repo.Migrations.RenameFooToBar do
use Versioned.Migration
def change do
rename_versioned_column("my_table", :foo, to: :bar)
end
end
Renames a table table and its versioned counterpart.
Note: If the table is cars
, then cars_versions
has a car_id
field. If
the table is being renamed to automobiles
, then after using this macro,
you'll want to also do something like the following in order to rename the
car_id
field in the versions table to automobile_id
.
rename table("automobiles_versions"), :car_id, to: :automobile_id
Example
defmodule MyApp.Repo.Migrations.RenameMyTable do
use Versioned.Migration
def change do
rename_versioned_table("my_table", "my_new_table")
end
end