migration.exs (3839B)
1 defmodule Ecto.Integration.Migration do 2 use Ecto.Migration 3 4 def change do 5 # IO.puts "TESTING MIGRATION LOCK" 6 # Process.sleep(10000) 7 8 create table(:users, comment: "users table") do 9 add :name, :string, comment: "name column" 10 add :custom_id, :uuid 11 timestamps() 12 end 13 14 create table(:posts) do 15 add :title, :string, size: 100 16 add :counter, :integer 17 add :blob, :binary 18 add :bid, :binary_id 19 add :uuid, :uuid 20 add :meta, :map 21 add :links, {:map, :string} 22 add :intensities, {:map, :float} 23 add :public, :boolean 24 add :cost, :decimal, precision: 2, scale: 1 25 add :visits, :integer 26 add :wrapped_visits, :integer 27 add :intensity, :float 28 add :author_id, :integer 29 add :posted, :date 30 timestamps(null: true) 31 end 32 33 create table(:posts_users, primary_key: false) do 34 add :post_id, references(:posts) 35 add :user_id, references(:users) 36 end 37 38 create table(:posts_users_pk) do 39 add :post_id, references(:posts) 40 add :user_id, references(:users) 41 timestamps() 42 end 43 44 # Add a unique index on uuid. We use this 45 # to verify the behaviour that the index 46 # only matters if the UUID column is not NULL. 47 create unique_index(:posts, [:uuid], comment: "posts index") 48 49 create table(:permalinks) do 50 add :uniform_resource_locator, :string 51 add :title, :string 52 add :post_id, references(:posts) 53 add :user_id, references(:users) 54 end 55 56 create unique_index(:permalinks, [:post_id]) 57 create unique_index(:permalinks, [:uniform_resource_locator]) 58 59 create table(:comments) do 60 add :text, :string, size: 100 61 add :lock_version, :integer, default: 1 62 add :post_id, references(:posts) 63 add :author_id, references(:users) 64 end 65 66 create table(:customs, primary_key: false) do 67 add :bid, :binary_id, primary_key: true 68 add :uuid, :uuid 69 end 70 71 create unique_index(:customs, [:uuid]) 72 73 create table(:customs_customs, primary_key: false) do 74 add :custom_id1, references(:customs, column: :bid, type: :binary_id) 75 add :custom_id2, references(:customs, column: :bid, type: :binary_id) 76 end 77 78 create table(:barebones) do 79 add :num, :integer 80 end 81 82 create table(:transactions) do 83 add :num, :integer 84 end 85 86 create table(:lock_counters) do 87 add :count, :integer 88 end 89 90 create table(:orders) do 91 add :item, :map 92 add :items, :map 93 add :meta, :map 94 add :permalink_id, references(:permalinks) 95 end 96 97 unless :array_type in ExUnit.configuration()[:exclude] do 98 create table(:tags) do 99 add :ints, {:array, :integer} 100 add :uuids, {:array, :uuid}, default: [] 101 add :items, {:array, :map} 102 end 103 104 create table(:array_loggings) do 105 add :uuids, {:array, :uuid}, default: [] 106 timestamps() 107 end 108 end 109 110 create table(:composite_pk, primary_key: false) do 111 add :a, :integer, primary_key: true 112 add :b, :integer, primary_key: true 113 add :name, :string 114 end 115 116 create table(:corrupted_pk, primary_key: false) do 117 add :a, :string 118 end 119 120 create table(:posts_users_composite_pk) do 121 add :post_id, references(:posts), primary_key: true 122 add :user_id, references(:users), primary_key: true 123 timestamps() 124 end 125 126 create unique_index(:posts_users_composite_pk, [:post_id, :user_id]) 127 128 create table(:usecs) do 129 add :naive_datetime_usec, :naive_datetime_usec 130 add :utc_datetime_usec, :utc_datetime_usec 131 end 132 133 create table(:bits) do 134 add :bit, :bit 135 end 136 137 create table(:loggings, primary_key: false) do 138 add :bid, :binary_id, primary_key: true 139 add :int, :integer 140 add :uuid, :uuid 141 timestamps() 142 end 143 end 144 end