diff --git a/app/models/invoicing_profile.rb b/app/models/invoicing_profile.rb new file mode 100644 index 000000000..27ede1620 --- /dev/null +++ b/app/models/invoicing_profile.rb @@ -0,0 +1,5 @@ +class InvoicingProfile < ActiveRecord::Base + belongs_to :user + belongs_to :address + belongs_to :organization +end diff --git a/db/migrate/20190521122429_create_invoicing_profiles.rb b/db/migrate/20190521122429_create_invoicing_profiles.rb new file mode 100644 index 000000000..eff7a3de5 --- /dev/null +++ b/db/migrate/20190521122429_create_invoicing_profiles.rb @@ -0,0 +1,13 @@ +class CreateInvoicingProfiles < ActiveRecord::Migration + def change + create_table :invoicing_profiles do |t| + t.references :user, index: true, foreign_key: true + t.string :first_name + t.string :last_name + t.references :address, index: true, foreign_key: true + t.references :organization, index: true, foreign_key: true + + t.timestamps null: false + end + end +end diff --git a/db/migrate/20190521124609_migrate_profile_to_invoicing_profile.rb b/db/migrate/20190521124609_migrate_profile_to_invoicing_profile.rb new file mode 100644 index 000000000..72b9cff50 --- /dev/null +++ b/db/migrate/20190521124609_migrate_profile_to_invoicing_profile.rb @@ -0,0 +1,13 @@ +class MigrateProfileToInvoicingProfile < ActiveRecord::Migration + def up + Profile.all.each do |p| + InvoicingProfile.create!( + user: p.user, + first_name: p.first_name, + last_name: p.last_name, + address: p.address, + organization: p.organization + ) + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 87bda757b..3f7243bd1 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,12 +11,12 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20190320091148) do +ActiveRecord::Schema.define(version: 20190521124609) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" - enable_extension "unaccent" enable_extension "pg_trgm" + enable_extension "unaccent" create_table "abuses", force: :cascade do |t| t.integer "signaled_id" @@ -287,6 +287,20 @@ ActiveRecord::Schema.define(version: 20190320091148) do add_index "invoices", ["user_id"], name: "index_invoices_on_user_id", using: :btree add_index "invoices", ["wallet_transaction_id"], name: "index_invoices_on_wallet_transaction_id", using: :btree + create_table "invoicing_profiles", force: :cascade do |t| + t.integer "user_id" + t.string "first_name" + t.string "last_name" + t.integer "address_id" + t.integer "organization_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + add_index "invoicing_profiles", ["address_id"], name: "index_invoicing_profiles_on_address_id", using: :btree + add_index "invoicing_profiles", ["organization_id"], name: "index_invoicing_profiles_on_organization_id", using: :btree + add_index "invoicing_profiles", ["user_id"], name: "index_invoicing_profiles_on_user_id", using: :btree + create_table "licences", force: :cascade do |t| t.string "name", null: false t.text "description" @@ -886,6 +900,9 @@ ActiveRecord::Schema.define(version: 20190320091148) do add_foreign_key "invoices", "coupons" add_foreign_key "invoices", "users", column: "operator_id" add_foreign_key "invoices", "wallet_transactions" + add_foreign_key "invoicing_profiles", "addresses" + add_foreign_key "invoicing_profiles", "organizations" + add_foreign_key "invoicing_profiles", "users" add_foreign_key "o_auth2_mappings", "o_auth2_providers" add_foreign_key "open_api_calls_count_tracings", "open_api_clients" add_foreign_key "organizations", "profiles" diff --git a/test/fixtures/invoicing_profiles.yml b/test/fixtures/invoicing_profiles.yml new file mode 100644 index 000000000..25edb3880 --- /dev/null +++ b/test/fixtures/invoicing_profiles.yml @@ -0,0 +1,15 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + user_id: + first_name: MyString + last_name: MyString + address_id: + organization_id: + +two: + user_id: + first_name: MyString + last_name: MyString + address_id: + organization_id: diff --git a/test/models/invoicing_profile_test.rb b/test/models/invoicing_profile_test.rb new file mode 100644 index 000000000..2cf8236d0 --- /dev/null +++ b/test/models/invoicing_profile_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class InvoicingProfileTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end