1
- # This migration comes from spree (originally 20220804073928)
2
1
class TransferDataToTranslatableTables < ActiveRecord ::Migration [ 7.0 ]
3
2
DEFAULT_LOCALE = 'en'
4
3
PRODUCTS_TABLE = 'spree_products'
@@ -10,19 +9,56 @@ def up
10
9
# Products
11
10
ActiveRecord ::Base . connection . execute ( "
12
11
INSERT INTO #{ PRODUCT_TRANSLATIONS_TABLE } (name, description, locale, spree_product_id, created_at, updated_at, meta_description, meta_keywords, meta_title, slug)
13
- SELECT name, description, '#{ DEFAULT_LOCALE } ' as locale, id, created_at, updated_at, meta_description, meta_keywords, meta_title, slug FROM #{ PRODUCTS_TABLE }
12
+ SELECT name, description, '#{ DEFAULT_LOCALE } ' as locale, id, created_at, updated_at, meta_description, meta_keywords, meta_title, slug FROM #{ PRODUCTS_TABLE }
13
+ " )
14
+ ActiveRecord ::Base . connection . execute ( "
15
+ UPDATE #{ PRODUCTS_TABLE }
16
+ SET name=null, description=null, meta_description=null, meta_keywords=null, meta_title=null, slug=null;
14
17
" )
15
18
#Taxons
16
19
ActiveRecord ::Base . connection . execute ( "
17
20
INSERT INTO #{ TAXON_TRANSLATIONS_TABLE } (name, description, locale, spree_taxon_id, created_at, updated_at)
18
- SELECT name, description, '#{ DEFAULT_LOCALE } ' as locale, id, created_at, updated_at FROM #{ TAXONS_TABLE }
21
+ SELECT name, description, '#{ DEFAULT_LOCALE } ' as locale, id, created_at, updated_at FROM #{ TAXONS_TABLE }
22
+ " )
23
+ ActiveRecord ::Base . connection . execute ( "
24
+ UPDATE #{ TAXONS_TABLE }
25
+ SET name=null, description=null
19
26
" )
20
27
end
21
28
22
29
def down
30
+ ActiveRecord ::Base . connection . execute ( "
31
+ UPDATE #{ PRODUCTS_TABLE } as products
32
+ SET (name,
33
+ description,
34
+ meta_description,
35
+ meta_keywords,
36
+ meta_title,
37
+ slug) =
38
+ (t_products.name,
39
+ t_products.description,
40
+ t_products.meta_description,
41
+ t_products.meta_keywords,
42
+ t_products.meta_title,
43
+ t_products.slug)
44
+ FROM #{ PRODUCT_TRANSLATIONS_TABLE } AS t_products
45
+ WHERE t_products.spree_product_id = products.id
46
+ " )
47
+
23
48
ActiveRecord ::Base . connection . execute ( "
24
49
TRUNCATE TABLE #{ PRODUCT_TRANSLATIONS_TABLE }
25
50
" )
51
+
52
+ ActiveRecord ::Base . connection . execute ( "
53
+ UPDATE #{ TAXONS_TABLE } as taxons
54
+ SET (name,
55
+ description) =
56
+ (t_taxons.name,
57
+ t_taxons.description)
58
+ FROM #{ TAXON_TRANSLATIONS_TABLE } AS t_taxons
59
+ WHERE t_taxons.spree_taxon_id = taxons.id
60
+ " )
61
+
26
62
ActiveRecord ::Base . connection . execute ( "
27
63
TRUNCATE TABLE #{ TAXON_TRANSLATIONS_TABLE }
28
64
" )
0 commit comments