Commit Graph

300 Commits

Author SHA1 Message Date
Luis Ramos
40dd307a35 Remove shipping method display on front_end option, it is not working and it's not straight forward to make it work correctly 2020-05-08 12:00:58 +01:00
Pau Perez
1903134e13 Add timestamps to OC schedule join table
This is critical to debug bugs related to subscriptions.

Essentially, `has_and_belongs_to_many` doesn't give us the option for
any other column that the foreign keys themselves:

> A has_and_belongs_to_many association creates a direct many-to-many
> connection with another model, with no intervening model.

Source: https://guides.rubyonrails.org/v3.2/association_basics.html#the-has_and_belongs_to_many-association

Note however, that there's no way to update an order_cycle_schedule,
that I can think of but `updated_at` doesn't do any harm.
2020-04-30 15:00:13 +02:00
Luis Ramos
0e5d7c1eb1 Add migration to drop dead spree_mail_methods table and some dead mail_methods preferences 2020-04-29 13:34:50 +01:00
Luis Ramos
248b0016d4 Remove trackers and google analytics 2020-04-27 18:40:33 +01:00
Maikel
b0eac1ecaa Merge branch 'master' into missing-indexes 2020-04-17 14:17:32 +10:00
Kristina Lim
e6cd33ee57 Increase max characters for locale in spree_users
There are many locales that have six (6) characters.
2020-04-07 15:08:49 +08:00
Matt-Yorkley
8a544f3ab3 Add missing indexes to spree_orders and spree_products 2020-04-04 10:12:15 +02:00
Luis Ramos
14fd9a121e Make versions.custom_data text so it can take longer lists 2020-03-27 11:34:01 +00:00
Luis Ramos
02008769e9 Make spree_payment.cvv_response_message without size limit so that long stripe redirect URLs can be stored there 2020-03-02 17:31:01 +00:00
Luis Ramos
2412658e51 Update db/schema timestamp according to last change 2020-02-20 11:41:49 +00:00
luisramos0
abd4f0b923 Add custom_data column to paper_trail versions table so we can track a specific list of ids in a model
Activate paper_trail in order_cycles and schedules and track each others ids

An alternative way of doing this would be to use a gem for paper_trail associations but this way we avoid adding a new dependency to the app
2020-02-07 10:06:58 +00:00
Matt-Yorkley
9e1b2eb4ca Fix migration mismatch
It looks like this was probably changed whilst resolving a merge conflict somewhere. The number doesn't match the last migration file, and it's breaking the ofn-install CI build (as well as migrations on fresh servers).
2019-11-05 22:58:14 +00:00
luisramos0
a6cb5903d6 Delete prototypes tables and all references in pages 2019-10-31 13:23:42 +00:00
Matt-Yorkley
34466c8218 Add order_cycle_id and distributor_id indexes to spree_orders table 2019-10-23 18:29:34 +01:00
luisramos0
a2bc61cb4d Remove unused field orders.shipping_method_id 2019-10-08 09:09:19 +01:00
luisramos0
f2b57057cd Add migration to delete all master variants from exchanges and replace them with standard variants 2019-10-07 14:53:44 +01:00
Pau Perez
ea41405209 Index spree_orders on various columns
The following query

```sql
SELECT spree_orders . *
FROM spree_orders
WHERE spree_orders . user_id = ?
AND spree_orders . completed_at IS ?
AND spree_orders . created_by_id = ?
ORDER BY created_at DESC LIMIT ?
```

performs quite badly even though LIMIT is always 1 because:

* ORDER BY requires sorting by a column which is not indexed therefore
a sequential scan is performed.
* Although `completed_at` is indexed, `user_id` and `created_by_id` are
not causing a sequential scan.

To make it worse this query is executed very often in the following
controllers among others also related to checkout:

* CartController#populate
* EnterprisesController#Shop
* LineItemsController#bought
* ShopController#products
* ShopController#order_cycle

In some cases this query alone accounts for 66.8% of the total time
of the endpoint.

Results

See by yourself. We move from 56.643ms to 0.077ms. Pretty neat.

```
openfoodnetwork=> explain analyze SELECT "spree_orders".* FROM "spree_orders" WHERE "spree_orders"."user_id" = 1 AND "spree_orders"."completed_at" IS NULL AND "spree_orders"."created_by_id" = 1 ORDER BY created_at DESC LIMIT 1;
                                                        QUERY PLAN
--------------------------------------------------------------------------------------------------------------------------
 Limit  (cost=11753.03..11753.04 rows=1 width=195) (actual time=56.580..56.580 rows=0 loops=1)
   ->  Sort  (cost=11753.03..11753.04 rows=1 width=195) (actual time=56.578..56.578 rows=0 loops=1)
         Sort Key: created_at DESC
         Sort Method: quicksort  Memory: 25kB
         ->  Seq Scan on spree_orders  (cost=0.00..11753.02 rows=1 width=195) (actual time=56.571..56.571 rows=0 loops=1)
               Filter: ((completed_at IS NULL) AND (user_id = 1) AND (created_by_id = 1))
               Rows Removed by Filter: 256135
 Planning time: 0.252 ms
 Execution time: 56.643 ms
(9 rows)

openfoodnetwork=> CREATE INDEX ON spree_orders (completed_at, user_id, created_by_id, created_at);
CREATE INDEX
openfoodnetwork=> explain analyze SELECT "spree_orders".* FROM "spree_orders" WHERE "spree_orders"."user_id" = 1 AND "spree_orders"."completed_at" IS NULL AND "spree_orders"."created_by_id" = 1 ORDER BY created_at DESC LIMIT 1;
mit  (cost=8.45..8.46 rows=1 width=195) (actual time=0.030..0.030 rows=0 loops=1)
   ->  Sort  (cost=8.45..8.46 rows=1 width=195) (actual time=0.029..0.029 rows=0 loops=1)
         Sort Key: created_at DESC
         Sort Method: quicksort  Memory: 25kB
         ->  Index Scan using spree_orders_completed_at_user_id_created_by_id_created_at_idx on spree_orders  (cost=0.42..8.44 rows=1 width=195) (actual time=0.021..0.021 rows=0 loops=1)
               Index Cond: ((completed_at IS NULL) AND (user_id = 1) AND (created_by_id = 1))
 Planning time: 0.199 ms
 Execution time: 0.077 ms
```
2019-09-17 17:02:14 +02:00
luisramos0
2683efdd3c Add missing update to db/schema by running db:migrate
This was missed in PR 4242
2019-09-17 15:27:56 +01:00
Matt-Yorkley
f413ce2a27 Soft-delete price objects 2019-09-06 17:50:19 +01:00
Matt-Yorkley
fc9f61ecf8 Revert PR #4204
Temporarily reverting these changes for a quick release
2019-09-05 13:23:59 +01:00
Matt-Yorkley
50a1704994 Make prices soft-deletable 2019-08-30 20:11:32 +01:00
Jon Leighton
4398ea12b8 Convert several fields from string to text
See discussion here:
https://github.com/openfoodfoundation/openfoodnetwork/pull/3751#issuecomment-503416955

Fixes #3192.

I have also done a pass over the schema to identify other fields which
would benefit from being a text rather than a string. However, I ignored
all `spree_*` tables because I didn’t want to mess up the ‘default’
Spree schema.
2019-07-09 13:11:30 +10:00
luisramos0
189865fd80 Make stock locations backorderable_default false.
This is required because when the default stock location is created, the backorderable_default column doesnt exist and when this column is created, the initial default is true. This is why we need to force it to false here. This column is the default value for on_demand which must be false.
2019-05-10 22:00:24 +01:00
Michael Hughes
9e56198092 references to payment_enterprise_id removed, new migration created 2019-05-04 16:32:48 +01:00
luisramos0
42d1d3eff6 Migrate spree_variants.on_demand to spree_stock_items.backorderable 2019-05-02 10:59:27 +01:00
Maikel
74aea76c4c Merge pull request #3609 from luisramos0/2-0-delete-acct-invoices-last-bit
[Spree Upgrade] Finish up deleting account invoices
2019-03-28 13:42:01 +11:00
luisramos0
c1d14686a6 Merge branch 'master' into 2-0-stable-Mar22 2019-03-22 10:55:17 +00:00
luisramos0
804375d1aa Delete obsolete pending delayed jobs related to the deleted account invoices feature 2019-03-20 11:24:57 +00:00
luisramos0
78d7222364 Drop account invoices and billable periods tables, the feature has been deleted 2019-03-20 11:19:48 +00:00
luisramos0
0bfeabbb3e Add migration to create default shipping category and set it in shipping methods and products that do not have a shipping category yet
This is a modified version of this spree migration: af16cf1d74
2019-03-13 15:36:21 +00:00
luisramos0
86f9b3d663 Delete product_distributions: drop table and remove models, controllers and BO edit page 2019-03-13 11:47:50 +00:00
luisramos0
0501db1782 Remove changes related to enterprise trials as they dont make sense without business models and account invoices 2019-02-25 14:37:16 +00:00
luisramos0
a870299ced Delete preferences and adjustments related to account invoices 2019-02-25 14:37:16 +00:00
luisramos0
e28f9a7c84 Merge branch 'master' into 2-0-stable-jan-8th 2019-01-08 14:29:50 +00:00
Kristina Lim
4c0c0bbfd0 Simplify stock configuration in existing variant overrides 2018-12-07 14:40:15 +08:00
luisramos0
3776b891ce Merge branch 'master' into 2-0-stable-dec-3rd 2018-12-03 15:30:16 +00:00
Maikel Linke
285346fcda Update schema for latest migration
I feel embarrased that this is the second follow up of my last
migration: https://github.com/openfoodfoundation/openfoodnetwork/pull/3126

The last migration didn't change any database structure, but the schema
still needs the latest migration version. Otherwise it will display
pending migrations when setting up the database.

This commit allows to run `bundle exec rake db:reset` in development
without the following message:

  Run `rake db:migrate` to update your database then try again.
  You have 1 pending migrations:
    20181123012635 AssociateCustomersToUsers

The next pull request with a migration would have solved this problem as
well.
2018-11-29 10:29:56 +11:00
luisramos0
fcdb5cd7af Merge branch 'master' into 2-0-stable-nov-8th 2018-11-08 11:18:54 +00:00
luisramos0
b7ffde795a Add migration to update calculator class name of weight calculators 2018-11-07 09:54:53 +00:00
luisramos0
079d4e0bf5 Fix variant_overrides permissions for overrides that belong to the supplier herself 2018-10-31 11:26:15 +00:00
luisramos0
d375bb8c55 Migration: Revoke variant overrides without permissions 2018-10-20 12:32:55 +01:00
luisramos0
87cd73ddba Merge branch 'master' into 2-0-stable-oct 2018-10-15 17:09:26 +01:00
Pau Perez
60d05a941c Fix variants with 'weight' and missing unit_value
This adds a data migration to fix those cases. It defaults to showing
1 unit of the specified weight. That is, if the user chose Kg, it'll
display 1 as unit.

Note that migration logs the process in a log/migrate.log file separate
from the regular Rails log/production.log file.

When you run the migration you'll see something like:

  Fixing variants missing unit_value...

  Processing variant 12...
  Succesfully fixed variant 12

  Done!

This helps auditing the changes applied and debug any possible failure
scenarios. You can delete it once all is ok.
2018-10-11 15:52:40 +02:00
Pau Pérez Fabregat
99ba9d7d1b Merge branch '2-0-stable' into unit-test-variant-stock 2018-09-19 15:41:21 +02:00
luisramos0
524f9af148 Drop unused db column line_items.shipping_method_name 2018-09-19 11:38:19 +01:00
luisramos0
c00e6a5dc7 Added DB uniqueness constraint on order_id to shipments
By forbidding more than a row per order in the spree_shipments table we ensure all orders have no more than one shipment associated
2018-09-11 00:24:50 +01:00
Pau Perez
cd53ec1a4f Replace exception with DB uniqueness constraint
By forbidding more than a row per variant in the spree_stock_items we
can ensure all variants have a single stock_item associated.
2018-09-06 13:21:22 +02:00
luisramos0
89d51d75ae Merge branch 'master' into 2-0-stable-sept 2018-09-04 17:43:20 +01:00
luisramos0
91e57cb893 Removed Cart table, its dependency on spree orders table and removed some more dead code related to this 2018-08-15 23:29:28 +01:00
Pau Perez
43bf7293bf Merge branch 'master' into 2-0-stable
* master: (125 commits)
  Fix syntax error in GETTING_STARTED.md
  Fix syntax error in README.md
  Fix link syntax errors in REAME.md and GETTING_STARTED.md
  Style recently merged code
  Update gem i18n-js to pick up locale changes
  Fix embedded shopfront menu responsiveness
  Add communications links to README
  Fix script/setup by making it less clever
  Change import and reset logic to work with first page
  Move options to first page
  Fix wrong sort predicates in customer index
  Reset reverse when clicking another column to sort
  Move logic for toggling by column into SortOptions
  Generalize sorting through SortOptions service
  Remove unused sorting preferences in ColumnsCtrl
  Fix frontend sorting in "Bulk Order Management"
  Fix frontend sorting in "Customers" index
  Change sorting to be done in ascending order first
  Wrap rows in customer index with TBODY tag
  Update .rubocop_todo.yml
  ...
2018-07-27 10:21:47 +02:00