SlideShare une entreprise Scribd logo
1  sur  78
© 2019 Magento, Inc. Page | 1
Magento 2.3
Declarative Schema
© 2019 Magento, Inc.
.
Page | 2
Lead Developer at BORN Group
Atish Goswami
© 2019 Magento, Inc. Page | 3
Agenda
© 2019 Magento, Inc. Page | 4
Agenda
• What is Declarative Schema ?
• Declaring table schemes
• Updating existing table schemes
• New CLI commands and arguments
• Schema Rollback
© 2019 Magento, Inc. Page | 5
Not In Scope
© 2019 Magento, Inc. Page | 6
Not in Scope
• Applying Data Patches
• Patch Rollbacks
• Schema Patches (Trigger/Stored Procedures)
© 2019 Magento, Inc. Page | 7
What is Declarative
Schema ?
© 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
© 2019 Magento, Inc. Page | 9
Why Declarative Schema ?
© 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
© 2019 Magento, Inc. Page | 11
Will Declarative Schema
help ?
© 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 *
© 2019 Magento, Inc. Page | 13
Getting Started
© 2019 Magento, Inc. Page | 14
<module_root>/registration.php
© 2019 Magento, Inc. Page | 15
<module_root>/etc/module.xml
Note : Declarative Schema does not require version number
© 2019 Magento, Inc. Page | 16
<module_root>/etc/db_schema.xml
New xml file introduced by Declarative Schema
© 2019 Magento, Inc. Page | 17
Declaring a table
© 2019 Magento, Inc. Page | 18
© 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
© 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
© 2019 Magento, Inc. Page | 21
Declaring integer columns
© 2019 Magento, Inc. Page | 22
<module_root>/etc/db_schema.xml
© 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)
© 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
© 2019 Magento, Inc. Page | 25
Declaring text columns
© 2019 Magento, Inc. Page | 26
© 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
© 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
© 2019 Magento, Inc. Page | 29
Declaring binary columns
© 2019 Magento, Inc. Page | 30
© 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
© 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
© 2019 Magento, Inc. Page | 33
Declaring decimal
columns
© 2019 Magento, Inc. Page | 34
© 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
© 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
© 2019 Magento, Inc. Page | 37
Declaring a time column
© 2019 Magento, Inc. Page | 38
© 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
© 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
© 2019 Magento, Inc. Page | 41
Declaring a primary key
© 2019 Magento, Inc. Page | 42
© 2019 Magento, Inc. Page | 43
Declaring a foreign key
© 2019 Magento, Inc. Page | 44
© 2019 Magento, Inc. Page | 45
Declaring a unique key
© 2019 Magento, Inc. Page | 46
© 2019 Magento, Inc. Page | 47
Declaring an index
© 2019 Magento, Inc. Page | 48
© 2019 Magento, Inc. Page | 49
<index/> Attributes
• indexType
– fulltext
– hash
– btree
© 2019 Magento, Inc. Page | 50
Generating
db_schema_whitelist.json
© 2019 Magento, Inc. Page | 51
© 2019 Magento, Inc. Page | 52
© 2019 Magento, Inc. Page | 53
<module_root>/etc/db_schema_whitelist.json
© 2019 Magento, Inc. Page | 54
© 2019 Magento, Inc. Page | 55
Testing with dry-run
© 2019 Magento, Inc. Page | 56
© 2019 Magento, Inc. Page | 57
© 2019 Magento, Inc. Page | 58
var/log/dry-run-installation.log
© 2019 Magento, Inc. Page | 59
© 2019 Magento, Inc. Page | 60
Applying Database
Schema
© 2019 Magento, Inc. Page | 61
© 2019 Magento, Inc. Page | 62
Modifying the table
column
© 2019 Magento, Inc. Page | 63
© 2019 Magento, Inc. Page | 64
© 2019 Magento, Inc. Page | 65
© 2019 Magento, Inc. Page | 66
Testing with safe-mode
© 2019 Magento, Inc. Page | 67
Destructive Operations
• Deleting a table
• Deleting a column
• Reducing column length
• Changing column precision
• Changing column type
© 2019 Magento, Inc. Page | 68
© 2019 Magento, Inc. Page | 69
var/declarative_dumps_csv/
{column_name_column_type_other_dimensions}.csv
var/declarative_dumps_csv/{table_name}.csv
© 2019 Magento, Inc. Page | 70
Restoring Schema Data
© 2019 Magento, Inc. Page | 71
© 2019 Magento, Inc. Page | 72
Uninstalling a Module
© 2019 Magento, Inc. Page | 73
© 2019 Magento, Inc. Page | 74
Converting Setup Script
to Declarative Schema
© 2019 Magento, Inc. Page | 75
© 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.
© 2019 Magento, Inc. Page | 77
Questions ?
© 2019 Magento, Inc. Page | 78
Thank You

Contenu connexe

Tendances

[Final] ReactJS presentation
[Final] ReactJS presentation[Final] ReactJS presentation
[Final] ReactJS presentation
洪 鹏发
 
e-Learning Management System : a Critical Study
e-Learning Management System : a Critical Studye-Learning Management System : a Critical Study
e-Learning Management System : a Critical Study
Kaustav Saha
 

Tendances (20)

Angular - Chapter 7 - HTTP Services
Angular - Chapter 7 - HTTP ServicesAngular - Chapter 7 - HTTP Services
Angular - Chapter 7 - HTTP Services
 
AngularJS for Beginners
AngularJS for BeginnersAngularJS for Beginners
AngularJS for Beginners
 
Angular tutorial
Angular tutorialAngular tutorial
Angular tutorial
 
Angular 5 presentation for beginners
Angular 5 presentation for beginnersAngular 5 presentation for beginners
Angular 5 presentation for beginners
 
Spring MVC
Spring MVCSpring MVC
Spring MVC
 
Basics of VueJS
Basics of VueJSBasics of VueJS
Basics of VueJS
 
Validation Controls in asp.net
Validation Controls in asp.netValidation Controls in asp.net
Validation Controls in asp.net
 
Jsp/Servlet
Jsp/ServletJsp/Servlet
Jsp/Servlet
 
Introduction to Angularjs
Introduction to AngularjsIntroduction to Angularjs
Introduction to Angularjs
 
Design and Implementation of E-Commerce Site for Online Shopping.pdf
Design and Implementation of E-Commerce Site for Online Shopping.pdfDesign and Implementation of E-Commerce Site for Online Shopping.pdf
Design and Implementation of E-Commerce Site for Online Shopping.pdf
 
Tomcat
TomcatTomcat
Tomcat
 
SRS For Online Store
SRS For Online StoreSRS For Online Store
SRS For Online Store
 
OTMS-PPT-1moo4l.pptx
OTMS-PPT-1moo4l.pptxOTMS-PPT-1moo4l.pptx
OTMS-PPT-1moo4l.pptx
 
Introduction to angular with a simple but complete project
Introduction to angular with a simple but complete projectIntroduction to angular with a simple but complete project
Introduction to angular with a simple but complete project
 
Mongoose: MongoDB object modelling for Node.js
Mongoose: MongoDB object modelling for Node.jsMongoose: MongoDB object modelling for Node.js
Mongoose: MongoDB object modelling for Node.js
 
Angular 9
Angular 9 Angular 9
Angular 9
 
[Final] ReactJS presentation
[Final] ReactJS presentation[Final] ReactJS presentation
[Final] ReactJS presentation
 
Magento2.3 - GraphQL introduction
Magento2.3  - GraphQL introductionMagento2.3  - GraphQL introduction
Magento2.3 - GraphQL introduction
 
e-Learning Management System : a Critical Study
e-Learning Management System : a Critical Studye-Learning Management System : a Critical Study
e-Learning Management System : a Critical Study
 
Reactjs
Reactjs Reactjs
Reactjs
 

Similaire à Magento 2 Declarative Schema

Imagine recap-devhub
Imagine recap-devhubImagine recap-devhub
Imagine recap-devhub
Magento Dev
 
Memory Management Made Simple: Kevin Mcghee, Madelyn Olson
Memory Management Made Simple: Kevin Mcghee, Madelyn OlsonMemory Management Made Simple: Kevin Mcghee, Madelyn Olson
Memory Management Made Simple: Kevin Mcghee, Madelyn Olson
Redis Labs
 

Similaire à Magento 2 Declarative Schema (20)

Magento 2.3 Schema and Data Patches
Magento 2.3 Schema and Data PatchesMagento 2.3 Schema and Data Patches
Magento 2.3 Schema and Data Patches
 
Eugene Shaksuvarov - Tuning Magento 2 for Maximum Performance
Eugene Shaksuvarov - Tuning Magento 2 for Maximum PerformanceEugene Shaksuvarov - Tuning Magento 2 for Maximum Performance
Eugene Shaksuvarov - Tuning Magento 2 for Maximum Performance
 
Using Magento 2.3 MySQL Queues
Using Magento 2.3 MySQL QueuesUsing Magento 2.3 MySQL Queues
Using Magento 2.3 MySQL Queues
 
Backward Compatibility Developer's Guide in Magento 2. #MM17CZ
Backward Compatibility Developer's Guide in Magento 2. #MM17CZBackward Compatibility Developer's Guide in Magento 2. #MM17CZ
Backward Compatibility Developer's Guide in Magento 2. #MM17CZ
 
Backward Compatibility Developer's Guide in Magento 2
Backward Compatibility Developer's Guide in Magento 2Backward Compatibility Developer's Guide in Magento 2
Backward Compatibility Developer's Guide in Magento 2
 
Imagine recap-devhub
Imagine recap-devhubImagine recap-devhub
Imagine recap-devhub
 
Data harmony update 2021
Data harmony update 2021 Data harmony update 2021
Data harmony update 2021
 
Le novità di sql server 2019
Le novità di sql server 2019Le novità di sql server 2019
Le novità di sql server 2019
 
Oracle 12.2 - My Favorite Top 5 New or Improved Features
Oracle 12.2 - My Favorite Top 5 New or Improved FeaturesOracle 12.2 - My Favorite Top 5 New or Improved Features
Oracle 12.2 - My Favorite Top 5 New or Improved Features
 
Talentica - JS Meetup - Angular Schematics
Talentica - JS Meetup - Angular SchematicsTalentica - JS Meetup - Angular Schematics
Talentica - JS Meetup - Angular Schematics
 
Developing with .NET Core on AWS: What's New (DEV318-R1) - AWS re:Invent 2018
Developing with .NET Core on AWS: What's New (DEV318-R1) - AWS re:Invent 2018Developing with .NET Core on AWS: What's New (DEV318-R1) - AWS re:Invent 2018
Developing with .NET Core on AWS: What's New (DEV318-R1) - AWS re:Invent 2018
 
Hidden gems in cf2016
Hidden gems in cf2016Hidden gems in cf2016
Hidden gems in cf2016
 
Presto Strata London 2019: Cost-Based Optimizer for interactive SQL on anything
Presto Strata London 2019: Cost-Based Optimizer for interactive SQL on anythingPresto Strata London 2019: Cost-Based Optimizer for interactive SQL on anything
Presto Strata London 2019: Cost-Based Optimizer for interactive SQL on anything
 
Novedades de MongoDB 3.6
Novedades de MongoDB 3.6Novedades de MongoDB 3.6
Novedades de MongoDB 3.6
 
How to upgrade like a boss to MySQL 8.0 - PLE19
How to upgrade like a boss to MySQL 8.0 -  PLE19How to upgrade like a boss to MySQL 8.0 -  PLE19
How to upgrade like a boss to MySQL 8.0 - PLE19
 
Starburst Presto - CBO talk - Strata London 2019
Starburst Presto  - CBO talk - Strata London 2019Starburst Presto  - CBO talk - Strata London 2019
Starburst Presto - CBO talk - Strata London 2019
 
[AWS Innovate 온라인 컨퍼런스] Kubernetes와 SageMaker를 활용하여 Machine Learning 워크로드 관리하...
[AWS Innovate 온라인 컨퍼런스] Kubernetes와 SageMaker를 활용하여 Machine Learning 워크로드 관리하...[AWS Innovate 온라인 컨퍼런스] Kubernetes와 SageMaker를 활용하여 Machine Learning 워크로드 관리하...
[AWS Innovate 온라인 컨퍼런스] Kubernetes와 SageMaker를 활용하여 Machine Learning 워크로드 관리하...
 
Backwards Compatibility Developers Guide. #MM17NL
Backwards Compatibility Developers Guide. #MM17NLBackwards Compatibility Developers Guide. #MM17NL
Backwards Compatibility Developers Guide. #MM17NL
 
Memory Management Made Simple: Kevin Mcghee, Madelyn Olson
Memory Management Made Simple: Kevin Mcghee, Madelyn OlsonMemory Management Made Simple: Kevin Mcghee, Madelyn Olson
Memory Management Made Simple: Kevin Mcghee, Madelyn Olson
 
MuleSoft Meetup 3 Charlotte Presentation Slides
MuleSoft Meetup 3 Charlotte Presentation SlidesMuleSoft Meetup 3 Charlotte Presentation Slides
MuleSoft Meetup 3 Charlotte Presentation Slides
 

Dernier

introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
VishalKumarJha10
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 

Dernier (20)

Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...
 

Magento 2 Declarative Schema

  • 1. © 2019 Magento, Inc. Page | 1 Magento 2.3 Declarative Schema
  • 2. © 2019 Magento, Inc. . Page | 2 Lead Developer at BORN Group Atish Goswami
  • 3. © 2019 Magento, Inc. Page | 3 Agenda
  • 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. © 2019 Magento, Inc. Page | 5 Not In Scope
  • 6. © 2019 Magento, Inc. Page | 6 Not in Scope • Applying Data Patches • Patch Rollbacks • Schema Patches (Trigger/Stored Procedures)
  • 7. © 2019 Magento, Inc. Page | 7 What is Declarative Schema ?
  • 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. © 2019 Magento, Inc. Page | 9 Why Declarative Schema ?
  • 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. © 2019 Magento, Inc. Page | 11 Will Declarative Schema help ?
  • 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. © 2019 Magento, Inc. Page | 13 Getting Started
  • 14. © 2019 Magento, Inc. Page | 14 <module_root>/registration.php
  • 15. © 2019 Magento, Inc. Page | 15 <module_root>/etc/module.xml Note : Declarative Schema does not require version number
  • 16. © 2019 Magento, Inc. Page | 16 <module_root>/etc/db_schema.xml New xml file introduced by Declarative Schema
  • 17. © 2019 Magento, Inc. Page | 17 Declaring a table
  • 18. © 2019 Magento, Inc. Page | 18
  • 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. © 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. © 2019 Magento, Inc. Page | 21 Declaring integer columns
  • 22. © 2019 Magento, Inc. Page | 22 <module_root>/etc/db_schema.xml
  • 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. © 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. © 2019 Magento, Inc. Page | 25 Declaring text columns
  • 26. © 2019 Magento, Inc. Page | 26
  • 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. © 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. © 2019 Magento, Inc. Page | 29 Declaring binary columns
  • 30. © 2019 Magento, Inc. Page | 30
  • 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. © 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. © 2019 Magento, Inc. Page | 33 Declaring decimal columns
  • 34. © 2019 Magento, Inc. Page | 34
  • 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. © 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. © 2019 Magento, Inc. Page | 37 Declaring a time column
  • 38. © 2019 Magento, Inc. Page | 38
  • 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. © 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. © 2019 Magento, Inc. Page | 41 Declaring a primary key
  • 42. © 2019 Magento, Inc. Page | 42
  • 43. © 2019 Magento, Inc. Page | 43 Declaring a foreign key
  • 44. © 2019 Magento, Inc. Page | 44
  • 45. © 2019 Magento, Inc. Page | 45 Declaring a unique key
  • 46. © 2019 Magento, Inc. Page | 46
  • 47. © 2019 Magento, Inc. Page | 47 Declaring an index
  • 48. © 2019 Magento, Inc. Page | 48
  • 49. © 2019 Magento, Inc. Page | 49 <index/> Attributes • indexType – fulltext – hash – btree
  • 50. © 2019 Magento, Inc. Page | 50 Generating db_schema_whitelist.json
  • 51. © 2019 Magento, Inc. Page | 51
  • 52. © 2019 Magento, Inc. Page | 52
  • 53. © 2019 Magento, Inc. Page | 53 <module_root>/etc/db_schema_whitelist.json
  • 54. © 2019 Magento, Inc. Page | 54
  • 55. © 2019 Magento, Inc. Page | 55 Testing with dry-run
  • 56. © 2019 Magento, Inc. Page | 56
  • 57. © 2019 Magento, Inc. Page | 57
  • 58. © 2019 Magento, Inc. Page | 58 var/log/dry-run-installation.log
  • 59. © 2019 Magento, Inc. Page | 59
  • 60. © 2019 Magento, Inc. Page | 60 Applying Database Schema
  • 61. © 2019 Magento, Inc. Page | 61
  • 62. © 2019 Magento, Inc. Page | 62 Modifying the table column
  • 63. © 2019 Magento, Inc. Page | 63
  • 64. © 2019 Magento, Inc. Page | 64
  • 65. © 2019 Magento, Inc. Page | 65
  • 66. © 2019 Magento, Inc. Page | 66 Testing with safe-mode
  • 67. © 2019 Magento, Inc. Page | 67 Destructive Operations • Deleting a table • Deleting a column • Reducing column length • Changing column precision • Changing column type
  • 68. © 2019 Magento, Inc. Page | 68
  • 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. © 2019 Magento, Inc. Page | 70 Restoring Schema Data
  • 71. © 2019 Magento, Inc. Page | 71
  • 72. © 2019 Magento, Inc. Page | 72 Uninstalling a Module
  • 73. © 2019 Magento, Inc. Page | 73
  • 74. © 2019 Magento, Inc. Page | 74 Converting Setup Script to Declarative Schema
  • 75. © 2019 Magento, Inc. Page | 75
  • 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. © 2019 Magento, Inc. Page | 77 Questions ?
  • 78. © 2019 Magento, Inc. Page | 78 Thank You