Ce diaporama a bien été signalé.
Nous utilisons votre profil LinkedIn et vos données d’activité pour vous proposer des publicités personnalisées et pertinentes. Vous pouvez changer vos préférences de publicités à tout moment.

Magento 2 Declarative Schema

1 460 vues

Publié le

Magento 2.3 Introduced Declarative Schema a new approach to manage schema migration
#M2BLR

Publié dans : Logiciels
  • Soyez le premier à commenter

Magento 2 Declarative Schema

  1. 1. © 2019 Magento, Inc. Page | 1 Magento 2.3 Declarative Schema
  2. 2. © 2019 Magento, Inc. . Page | 2 Lead Developer at BORN Group Atish Goswami
  3. 3. © 2019 Magento, Inc. Page | 3 Agenda
  4. 4. © 2019 Magento, Inc. Page | 4 Agenda • What is Declarative Schema ? • Declaring table schemes • Updating existing table schemes • New CLI commands and arguments • Schema Rollback
  5. 5. © 2019 Magento, Inc. Page | 5 Not In Scope
  6. 6. © 2019 Magento, Inc. Page | 6 Not in Scope • Applying Data Patches • Patch Rollbacks • Schema Patches (Trigger/Stored Procedures)
  7. 7. © 2019 Magento, Inc. Page | 7 What is Declarative Schema ?
  8. 8. © 2019 Magento, Inc. Page | 8 Declarative Schema • Newer way of handling Setup Script Operations • Setup Scripts are still supported in 2.3.x versions (EOL unknown) • Might be Backported to 2.2.x newer versions • Declarative Schema and Setup Scripts don’t work together • If developing backwards compatible modules use Setup Script
  9. 9. © 2019 Magento, Inc. Page | 9 Why Declarative Schema ?
  10. 10. © 2019 Magento, Inc. Page | 10 Issues with Setup Scripts • Setup Scripts get complicated to manage overtime • Module sequencing needs to be handled properly • Confusing to manage Install vs Upgrade scripts • Version number mishap happens • No Rollbacks
  11. 11. © 2019 Magento, Inc. Page | 11 Will Declarative Schema help ?
  12. 12. © 2019 Magento, Inc. Page | 12 Declarative Schema Offers • Avoidance of missed/repeated SQL operations • Installation testing using dry-run mode • Performance optimization • Support for rollbacks *
  13. 13. © 2019 Magento, Inc. Page | 13 Getting Started
  14. 14. © 2019 Magento, Inc. Page | 14 <module_root>/registration.php
  15. 15. © 2019 Magento, Inc. Page | 15 <module_root>/etc/module.xml Note : Declarative Schema does not require version number
  16. 16. © 2019 Magento, Inc. Page | 16 <module_root>/etc/db_schema.xml New xml file introduced by Declarative Schema
  17. 17. © 2019 Magento, Inc. Page | 17 Declaring a table
  18. 18. © 2019 Magento, Inc. Page | 18
  19. 19. © 2019 Magento, Inc. Page | 19 <table/> Attributes • name – Name of the table – Required • resource (default) – Database connection to use for the operation – Allowed values – default, sales, checkout • engine (innodb) – MySQL Table engine – Allowed values – innodb, memory
  20. 20. © 2019 Magento, Inc. Page | 20 <table/> Attributes (Contd) • comment (not comments added) – Comment Relating the table • charset (utf8) – Charset for the table • collation (utf8_general_ci) – Collation to match the charset • onCreate (empty) – Helps trigger a task after the table is created
  21. 21. © 2019 Magento, Inc. Page | 21 Declaring integer columns
  22. 22. © 2019 Magento, Inc. Page | 22 <module_root>/etc/db_schema.xml
  23. 23. © 2019 Magento, Inc. Page | 23 <column/> Integer Attributes • name – Name of the column – Required • xsi:type – Allowed Values – (tinyint, int, smallint, bigint, boolean) – Required • default (NULL) – Provide default column value – Can provide only value as integer • padding (tinyint[2], int[11], smallint[5], bigint[20], boolean[1]) – Padding values for the integer type columns – Allowed Values (2 - 1024)
  24. 24. © 2019 Magento, Inc. Page | 24 <column/> Integer Attributes • unsigned (false) – If column contains negative values need to be true • identity (false) – If true column will be auto increment – The column need to be declared in primary index as well • nullable (true) – If column will have NULL values • comment (no comments are added) – Comment for the column • onCreate (empty) – Helps trigger a task after the column is created
  25. 25. © 2019 Magento, Inc. Page | 25 Declaring text columns
  26. 26. © 2019 Magento, Inc. Page | 26
  27. 27. © 2019 Magento, Inc. Page | 27 <column/> Text Attributes • name – Name of the Column – Required • xsi:type – Allowed Values – (varchar, text, mediumtext, longtext) – Required • default – Provide default column value – Can provided only for varchar • length – Length of the field – varchar allowed max length is 1024 – text mediumtext longtext length can’t be defined
  28. 28. © 2019 Magento, Inc. Page | 28 <column/> Text Attributes • comment (no comments are added) – Comment for the column • nullable (true) – If column will have NULL values • onCreate (empty) – Helps trigger a task after the column is created
  29. 29. © 2019 Magento, Inc. Page | 29 Declaring binary columns
  30. 30. © 2019 Magento, Inc. Page | 30
  31. 31. © 2019 Magento, Inc. Page | 31 <column/> Text Attributes • xsi:type – Allowed Values – (varbinary, blob, mediumblob, longblob) – Required • default – Provide default column value – Can provided only for varbinary • length – Length of the field – varbinary allowed max length is 255 – blob mediumblob longblob length can’t be defined • comment (no comments are added) – Comment for the column
  32. 32. © 2019 Magento, Inc. Page | 32 <column/> Text Attributes • nullable (true) – If column will have NULL values • onCreate (empty) – Helps trigger a task after the column is created
  33. 33. © 2019 Magento, Inc. Page | 33 Declaring decimal columns
  34. 34. © 2019 Magento, Inc. Page | 34
  35. 35. © 2019 Magento, Inc. Page | 35 <column/> Text Attributes • xsi:type – Allowed Values – (decimal, float, double) – Required • default – Provide default column value • precision – Total digits of the decimal numbers • scale – Total digits after the decimal point • comment (no comments are added) – Comment for the column
  36. 36. © 2019 Magento, Inc. Page | 36 <column/> Text Attributes • nullable (true) – If column will have NULL values • unsigned (false) – If column contains negative values need to be true • onCreate (empty) – Helps trigger a task after the column is created
  37. 37. © 2019 Magento, Inc. Page | 37 Declaring a time column
  38. 38. © 2019 Magento, Inc. Page | 38
  39. 39. © 2019 Magento, Inc. Page | 39 <column/> Text Attributes • name – Name of the column – Required • xsi:type – Allowed Values – (timestamp, datetime, date) – Required • default – Provide default column value – Allowed Values – (CURRENT_TIMESTAMP, 0, NULL) • comment (no comments are added) – Comment for the column • on_update (false) – MySQL on update will be implemented
  40. 40. © 2019 Magento, Inc. Page | 40 <column/> Text Attributes • nullable (true) – If column will have NULL values • onCreate (empty) – Helps trigger a task after the column is created
  41. 41. © 2019 Magento, Inc. Page | 41 Declaring a primary key
  42. 42. © 2019 Magento, Inc. Page | 42
  43. 43. © 2019 Magento, Inc. Page | 43 Declaring a foreign key
  44. 44. © 2019 Magento, Inc. Page | 44
  45. 45. © 2019 Magento, Inc. Page | 45 Declaring a unique key
  46. 46. © 2019 Magento, Inc. Page | 46
  47. 47. © 2019 Magento, Inc. Page | 47 Declaring an index
  48. 48. © 2019 Magento, Inc. Page | 48
  49. 49. © 2019 Magento, Inc. Page | 49 <index/> Attributes • indexType – fulltext – hash – btree
  50. 50. © 2019 Magento, Inc. Page | 50 Generating db_schema_whitelist.json
  51. 51. © 2019 Magento, Inc. Page | 51
  52. 52. © 2019 Magento, Inc. Page | 52
  53. 53. © 2019 Magento, Inc. Page | 53 <module_root>/etc/db_schema_whitelist.json
  54. 54. © 2019 Magento, Inc. Page | 54
  55. 55. © 2019 Magento, Inc. Page | 55 Testing with dry-run
  56. 56. © 2019 Magento, Inc. Page | 56
  57. 57. © 2019 Magento, Inc. Page | 57
  58. 58. © 2019 Magento, Inc. Page | 58 var/log/dry-run-installation.log
  59. 59. © 2019 Magento, Inc. Page | 59
  60. 60. © 2019 Magento, Inc. Page | 60 Applying Database Schema
  61. 61. © 2019 Magento, Inc. Page | 61
  62. 62. © 2019 Magento, Inc. Page | 62 Modifying the table column
  63. 63. © 2019 Magento, Inc. Page | 63
  64. 64. © 2019 Magento, Inc. Page | 64
  65. 65. © 2019 Magento, Inc. Page | 65
  66. 66. © 2019 Magento, Inc. Page | 66 Testing with safe-mode
  67. 67. © 2019 Magento, Inc. Page | 67 Destructive Operations • Deleting a table • Deleting a column • Reducing column length • Changing column precision • Changing column type
  68. 68. © 2019 Magento, Inc. Page | 68
  69. 69. © 2019 Magento, Inc. Page | 69 var/declarative_dumps_csv/ {column_name_column_type_other_dimensions}.csv var/declarative_dumps_csv/{table_name}.csv
  70. 70. © 2019 Magento, Inc. Page | 70 Restoring Schema Data
  71. 71. © 2019 Magento, Inc. Page | 71
  72. 72. © 2019 Magento, Inc. Page | 72 Uninstalling a Module
  73. 73. © 2019 Magento, Inc. Page | 73
  74. 74. © 2019 Magento, Inc. Page | 74 Converting Setup Script to Declarative Schema
  75. 75. © 2019 Magento, Inc. Page | 75
  76. 76. © 2019 Magento, Inc. Page | 76 Limitations • Custom DDL operations are ignored. It supports only DDL operations that are present in MagentoFrameworkDBAdapterPdoMysql • Raw SQL in InstallSchema or UpgradeSchema scripts are ignored. • DDL statements in the Recurring file won’t be transferred to the new schema because the file needs to run during each installation or upgrade.
  77. 77. © 2019 Magento, Inc. Page | 77 Questions ?
  78. 78. © 2019 Magento, Inc. Page | 78 Thank You

×