diff --git a/migrations/migrations/.DS_Store b/migrations/migrations/.DS_Store new file mode 100644 index 0000000..5008ddf Binary files /dev/null and b/migrations/migrations/.DS_Store differ diff --git a/migrations/migrations/20210630180628_create_widgets_table.down.fizz b/migrations/migrations/20210630180628_create_widgets_table.down.fizz new file mode 100644 index 0000000..e69de29 diff --git a/migrations/migrations/20210630180628_create_widgets_table.up.fizz b/migrations/migrations/20210630180628_create_widgets_table.up.fizz new file mode 100644 index 0000000..5f9107c --- /dev/null +++ b/migrations/migrations/20210630180628_create_widgets_table.up.fizz @@ -0,0 +1,12 @@ +create_table("widgets") { + t.Column("id", "integer", {primary: true}) + t.Column("name", "string", {"default": ""}) + t.Column("description", "text", {"default": ""}) + t.Column("inventory_level", "integer", {}) + t.Column("price", "integer", {}) +} + +sql("alter table widgets alter column created_at set default now();") +sql("alter table widgets alter column updated_at set default now();") + +sql("insert into widgets (name, description, inventory_level, price, created_at, updated_at) values ('Widget', 'A very nice widget.', 10, 1000, now(), now());") \ No newline at end of file diff --git a/migrations/migrations/20210630180635_create_transaction_status_table.down.fizz b/migrations/migrations/20210630180635_create_transaction_status_table.down.fizz new file mode 100644 index 0000000..e69de29 diff --git a/migrations/migrations/20210630180635_create_transaction_status_table.up.fizz b/migrations/migrations/20210630180635_create_transaction_status_table.up.fizz new file mode 100644 index 0000000..b7b9842 --- /dev/null +++ b/migrations/migrations/20210630180635_create_transaction_status_table.up.fizz @@ -0,0 +1,13 @@ +create_table("transaction_statuses") { + t.Column("id", "integer", {primary: true}) + t.Column("name", "string", {}) +} + +sql("alter table transaction_statuses alter column created_at set default now();") +sql("alter table transaction_statuses alter column updated_at set default now();") + +sql("insert into transaction_statuses (name) values ('Pending');") +sql("insert into transaction_statuses (name) values ('Cleared');") +sql("insert into transaction_statuses (name) values ('Declined');") +sql("insert into transaction_statuses (name) values ('Refunded');") +sql("insert into transaction_statuses (name) values ('Partially refunded');") \ No newline at end of file diff --git a/migrations/migrations/20210630181022_create_transaction_table.down.fizz b/migrations/migrations/20210630181022_create_transaction_table.down.fizz new file mode 100644 index 0000000..f9e1cee --- /dev/null +++ b/migrations/migrations/20210630181022_create_transaction_table.down.fizz @@ -0,0 +1 @@ +drop_table("transactions") \ No newline at end of file diff --git a/migrations/migrations/20210630181022_create_transaction_table.up.fizz b/migrations/migrations/20210630181022_create_transaction_table.up.fizz new file mode 100644 index 0000000..e5a1c1b --- /dev/null +++ b/migrations/migrations/20210630181022_create_transaction_table.up.fizz @@ -0,0 +1,16 @@ +create_table("transactions") { + t.Column("id", "integer", {primary: true}) + t.Column("amount", "integer", {}) + t.Column("currency", "string", {}) + t.Column("last_four", "string", {}) + t.Column("bank_return_code", "string", {}) + t.Column("transaction_status_id", "integer", {"unsigned": true}) +} + +sql("alter table transactions alter column created_at set default now();") +sql("alter table transactions alter column updated_at set default now();") + +add_foreign_key("transactions", "transaction_status_id", {"transaction_statuses": ["id"]}, { + "on_delete": "cascade", + "on_update": "cascade", +}) \ No newline at end of file diff --git a/migrations/migrations/20210630183342_create_orders_table.down.fizz b/migrations/migrations/20210630183342_create_orders_table.down.fizz new file mode 100644 index 0000000..93bee25 --- /dev/null +++ b/migrations/migrations/20210630183342_create_orders_table.down.fizz @@ -0,0 +1 @@ +drop_table("orders") \ No newline at end of file diff --git a/migrations/migrations/20210630183342_create_orders_table.up.fizz b/migrations/migrations/20210630183342_create_orders_table.up.fizz new file mode 100644 index 0000000..ba56ba6 --- /dev/null +++ b/migrations/migrations/20210630183342_create_orders_table.up.fizz @@ -0,0 +1,21 @@ +create_table("orders") { + t.Column("id", "integer", {primary: true}) + t.Column("widget_id", "integer", {"unsigned":true}) + t.Column("transaction_id", "integer", {"unsigned":true}) + t.Column("status_id", "integer", {"unsigned":true}) + t.Column("quantity", "integer", {}) + t.Column("amount", "integer", {}) +} + +sql("alter table orders alter column created_at set default now();") +sql("alter table orders alter column updated_at set default now();") + +add_foreign_key("orders", "widget_id", {"widgets": ["id"]}, { + "on_delete": "cascade", + "on_update": "cascade", +}) + +add_foreign_key("orders", "transaction_id", {"transactions": ["id"]}, { + "on_delete": "cascade", + "on_update": "cascade", +}) \ No newline at end of file diff --git a/migrations/migrations/20210630183733_create_statuses_table.down.fizz b/migrations/migrations/20210630183733_create_statuses_table.down.fizz new file mode 100644 index 0000000..030ea72 --- /dev/null +++ b/migrations/migrations/20210630183733_create_statuses_table.down.fizz @@ -0,0 +1 @@ +drop_table("statuses") \ No newline at end of file diff --git a/migrations/migrations/20210630183733_create_statuses_table.up.fizz b/migrations/migrations/20210630183733_create_statuses_table.up.fizz new file mode 100644 index 0000000..07a0977 --- /dev/null +++ b/migrations/migrations/20210630183733_create_statuses_table.up.fizz @@ -0,0 +1,16 @@ +create_table("statuses") { + t.Column("id", "integer", {primary: true}) + t.Column("name", "string", {}) +} + +sql("alter table statuses alter column created_at set default now();") +sql("alter table statuses alter column updated_at set default now();") + +sql("insert into statuses (name) values ('Cleared');") +sql("insert into statuses (name) values ('Refunded');") +sql("insert into statuses (name) values ('Cancelled');") + +add_foreign_key("orders", "status_id", {"statuses": ["id"]}, { + "on_delete": "cascade", + "on_update": "cascade", +}) diff --git a/migrations/migrations/20210630184028_create_users_table.down.fizz b/migrations/migrations/20210630184028_create_users_table.down.fizz new file mode 100644 index 0000000..87001e1 --- /dev/null +++ b/migrations/migrations/20210630184028_create_users_table.down.fizz @@ -0,0 +1 @@ +drop_table("users") \ No newline at end of file diff --git a/migrations/migrations/20210630184028_create_users_table.up.fizz b/migrations/migrations/20210630184028_create_users_table.up.fizz new file mode 100644 index 0000000..f64dae5 --- /dev/null +++ b/migrations/migrations/20210630184028_create_users_table.up.fizz @@ -0,0 +1,12 @@ +create_table("users") { + t.Column("id", "integer", {primary: true}) + t.Column("first_name", "string", {"size": 255}) + t.Column("last_name", "string", {"size": 255}) + t.Column("email", "string", {}) + t.Column("password", "string", {"size": 60}) +} + +sql("alter table users alter column created_at set default now();") +sql("alter table users alter column updated_at set default now();") + +sql("insert into users (first_name, last_name, email, password) values ('Admin','User','admin@example.com', '$2a$12$VR1wDmweaF3ZTVgEHiJrNOSi8VcS4j0eamr96A/7iOe8vlum3O3/q');")