-
Notifications
You must be signed in to change notification settings - Fork 105
309 add declarative schema generation #453
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
VitaliyBoyko
merged 6 commits into
magento:3.1.0-develop
from
bohdan-harniuk:309-add-declarative-schema-generation
Jan 19, 2021
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3a43929
309: Add declarative schema base dialog with table related fields
bohdan-harniuk 35d0e0d
309: Generation of base table xml
bohdan-harniuk 00c9171
309: Added columns, pk and pk index generation
bohdan-harniuk 57ce9f8
309: Code refactoring
bohdan-harniuk 7d9ac34
309: Added test for DbSchemaXmlGenerator
bohdan-harniuk 20a5a2d
309: Code refactoring after code review
bohdan-harniuk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
resources/fileTemplates/internal/Magento Module Declarative Schema XML.xml.ft
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0"?> | ||
<schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd"> | ||
</schema> |
18 changes: 18 additions & 0 deletions
18
resources/fileTemplates/internal/Magento Module Declarative Schema XML.xml.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<!-- | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
--> | ||
<html lang="en"> | ||
<body> | ||
<font face="verdana" size="-1"> | ||
<p> | ||
Declarative Schema aims to simplify the Magento installation and upgrade processes. The new declarative schema approach allows developers to declare the final desired state of the database and has the system adjust to it automatically, without performing redundant operations. Developers are no longer forced to write scripts for each new version. In addition, this approach allows data be deleted when a module is uninstalled. | ||
</p> | ||
<p> | ||
Read more about <a href="https://devdocs.magento.com/guides/v2.4/extension-dev-guide/declarative-schema/">Declarative Schema Overview</a>. | ||
</p> | ||
</font> | ||
</body> | ||
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/com/magento/idea/magento2plugin/actions/generation/NewDbSchemaAction.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
package com.magento.idea.magento2plugin.actions.generation; | ||
|
||
import com.intellij.ide.IdeView; | ||
import com.intellij.openapi.actionSystem.AnAction; | ||
import com.intellij.openapi.actionSystem.AnActionEvent; | ||
import com.intellij.openapi.actionSystem.CommonDataKeys; | ||
import com.intellij.openapi.actionSystem.DataContext; | ||
import com.intellij.openapi.actionSystem.LangDataKeys; | ||
import com.intellij.openapi.project.Project; | ||
import com.intellij.psi.PsiDirectory; | ||
import com.magento.idea.magento2plugin.MagentoIcons; | ||
import com.magento.idea.magento2plugin.actions.generation.dialog.NewDbSchemaDialog; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class NewDbSchemaAction extends AnAction { | ||
public static final String ACTION_NAME = "Declarative Schema XML"; | ||
public static final String ACTION_DESCRIPTION = "Create a new declarative schema XML"; | ||
|
||
/** | ||
* Constructor. | ||
*/ | ||
public NewDbSchemaAction() { | ||
super(ACTION_NAME, ACTION_DESCRIPTION, MagentoIcons.MODULE); | ||
} | ||
|
||
@Override | ||
public void actionPerformed(final @NotNull AnActionEvent event) { | ||
final DataContext dataContext = event.getDataContext(); | ||
final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext); | ||
if (view == null) { | ||
return; | ||
} | ||
|
||
final Project project = CommonDataKeys.PROJECT.getData(dataContext); | ||
if (project == null) { | ||
return; | ||
} | ||
|
||
final PsiDirectory directory = view.getOrChooseDirectory(); | ||
if (directory == null) { | ||
return; | ||
} | ||
NewDbSchemaDialog.open(project, directory); | ||
} | ||
|
||
@Override | ||
public boolean isDumbAware() { | ||
return false; | ||
} | ||
} |
98 changes: 98 additions & 0 deletions
98
src/com/magento/idea/magento2plugin/actions/generation/data/DbSchemaXmlData.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
package com.magento.idea.magento2plugin.actions.generation.data; | ||
|
||
import com.magento.idea.magento2plugin.magento.files.ModuleDbSchemaXml; | ||
import java.util.LinkedHashMap; | ||
import java.util.LinkedList; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class DbSchemaXmlData { | ||
private String tableName; | ||
private String tableResource; | ||
private String tableEngine; | ||
private String tableComment; | ||
private List<Map<String, String>> columns; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param tableName String | ||
* @param tableResource String | ||
* @param tableEngine String | ||
* @param tableComment String | ||
* @param columns List | ||
*/ | ||
public DbSchemaXmlData( | ||
final String tableName, | ||
final String tableResource, | ||
final String tableEngine, | ||
final String tableComment, | ||
final List<Map<String, String>> columns | ||
) { | ||
this.tableName = tableName; | ||
this.tableResource = tableResource; | ||
this.tableEngine = tableEngine; | ||
this.tableComment = tableComment; | ||
this.columns = columns; | ||
} | ||
|
||
public String getTableName() { | ||
return tableName; | ||
} | ||
|
||
public void setTableName(final String tableName) { | ||
this.tableName = tableName; | ||
} | ||
|
||
public String getTableResource() { | ||
return tableResource; | ||
} | ||
|
||
public void setTableResource(final String tableResource) { | ||
this.tableResource = tableResource; | ||
} | ||
|
||
public String getTableEngine() { | ||
return tableEngine; | ||
} | ||
|
||
public void setTableEngine(final String tableEngine) { | ||
this.tableEngine = tableEngine; | ||
} | ||
|
||
public String getTableComment() { | ||
return tableComment; | ||
} | ||
|
||
public void setTableComment(final String tableComment) { | ||
this.tableComment = tableComment; | ||
} | ||
|
||
public List<Map<String, String>> getColumns() { | ||
return new LinkedList<>(columns); | ||
} | ||
|
||
public void setColumns(final List<Map<String, String>> columns) { | ||
this.columns = columns; | ||
} | ||
|
||
/** | ||
* Get table attributes values map. | ||
* | ||
* @return Map | ||
*/ | ||
public Map<String, String> getTableAttributesMap() { | ||
final Map<String, String> tableAttributesData = new LinkedHashMap<>();//NOPMD | ||
tableAttributesData.put(ModuleDbSchemaXml.XML_ATTR_TABLE_NAME, getTableName()); | ||
tableAttributesData.put(ModuleDbSchemaXml.XML_ATTR_TABLE_RESOURCE, getTableResource()); | ||
tableAttributesData.put(ModuleDbSchemaXml.XML_ATTR_TABLE_ENGINE, getTableEngine()); | ||
tableAttributesData.put(ModuleDbSchemaXml.XML_ATTR_TABLE_COMMENT, getTableComment()); | ||
|
||
return tableAttributesData; | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
src/com/magento/idea/magento2plugin/actions/generation/data/ui/ComboBoxItemData.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
package com.magento.idea.magento2plugin.actions.generation.data.ui; | ||
|
||
/** | ||
* Data Models for storing ComboBox UI component item data. | ||
*/ | ||
public class ComboBoxItemData { | ||
private final String key; | ||
private final String text; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param key String | ||
* @param text String | ||
*/ | ||
public ComboBoxItemData(final String key, final String text) { | ||
this.key = key; | ||
this.text = text; | ||
} | ||
|
||
/** | ||
* Get key. | ||
* | ||
* @return String | ||
*/ | ||
public String getKey() { | ||
return key; | ||
} | ||
|
||
/** | ||
* Get Text. | ||
* | ||
* @return String | ||
*/ | ||
public String getText() { | ||
return text; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return this.getText(); | ||
} | ||
} |
106 changes: 106 additions & 0 deletions
106
...m/magento/idea/magento2plugin/actions/generation/data/util/DbSchemaXmlSourceDataUtil.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/* | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
package com.magento.idea.magento2plugin.actions.generation.data.util; | ||
|
||
import java.util.Arrays; | ||
import java.util.LinkedList; | ||
import java.util.List; | ||
|
||
public final class DbSchemaXmlSourceDataUtil { | ||
// currently available engines | ||
public static final String TABLE_ENGINE_INNODB = "innodb"; | ||
public static final String TABLE_ENGINE_MEMORY = "memory"; | ||
// currently available resources | ||
public static final String TABLE_RESOURCE_DEFAULT = "default"; | ||
public static final String TABLE_RESOURCE_CHECKOUT = "checkout"; | ||
public static final String TABLE_RESOURCE_SALES = "sales"; | ||
// available column types | ||
// binaries | ||
public static final String COLUMN_TYPE_BLOB = "blob"; | ||
public static final String COLUMN_TYPE_MEDIUMBLOB = "mediumblob"; | ||
public static final String COLUMN_TYPE_LONGBLOB = "longblob"; | ||
public static final String COLUMN_TYPE_VARBINARY = "varbinary"; | ||
// integers | ||
public static final String COLUMN_TYPE_TINYINT = "tinyint"; | ||
public static final String COLUMN_TYPE_SMALLINT = "smallint"; | ||
public static final String COLUMN_TYPE_INT = "int"; | ||
public static final String COLUMN_TYPE_BIGINT = "bigint"; | ||
// reals | ||
public static final String COLUMN_TYPE_DECIMAL = "decimal"; | ||
public static final String COLUMN_TYPE_DOUBLE = "double"; | ||
public static final String COLUMN_TYPE_FLOAT = "float"; | ||
// text | ||
public static final String COLUMN_TYPE_VARCHAR = "varchar"; | ||
public static final String COLUMN_TYPE_TEXT = "text"; | ||
public static final String COLUMN_TYPE_MEDIUMTEXT = "mediumtext"; | ||
public static final String COLUMN_TYPE_LONGTEXT = "longtext"; | ||
// boolean | ||
public static final String COLUMN_TYPE_BOOLEAN = "boolean"; | ||
// date | ||
public static final String COLUMN_TYPE_DATETIME = "datetime"; | ||
public static final String COLUMN_TYPE_DATE = "date"; | ||
public static final String COLUMN_TYPE_TIMESTAMP = "timestamp"; | ||
|
||
/** | ||
* Denying the possibility to initialize this class. | ||
*/ | ||
private DbSchemaXmlSourceDataUtil() {} | ||
|
||
/** | ||
* Get source list for available table engines. | ||
* | ||
* @return List | ||
*/ | ||
public static List<String> getTableEngineSource() { | ||
return new LinkedList<>(Arrays.asList( | ||
DbSchemaXmlSourceDataUtil.TABLE_ENGINE_INNODB, | ||
DbSchemaXmlSourceDataUtil.TABLE_ENGINE_MEMORY) | ||
); | ||
} | ||
|
||
/** | ||
* Get source list for available table resources. | ||
* | ||
* @return List | ||
*/ | ||
public static List<String> getTableResourceSource() { | ||
return new LinkedList<>(Arrays.asList( | ||
TABLE_RESOURCE_DEFAULT, | ||
TABLE_RESOURCE_CHECKOUT, | ||
TABLE_RESOURCE_SALES | ||
)); | ||
} | ||
|
||
/** | ||
* Get source list for available column types. | ||
* | ||
* @return List | ||
*/ | ||
public static List<String> getColumnTypes() { | ||
return new LinkedList<>(Arrays.asList( | ||
"", | ||
COLUMN_TYPE_BLOB, | ||
COLUMN_TYPE_MEDIUMBLOB, | ||
COLUMN_TYPE_LONGBLOB, | ||
COLUMN_TYPE_VARBINARY, | ||
COLUMN_TYPE_TINYINT, | ||
COLUMN_TYPE_SMALLINT, | ||
COLUMN_TYPE_INT, | ||
COLUMN_TYPE_BIGINT, | ||
COLUMN_TYPE_DECIMAL, | ||
COLUMN_TYPE_DOUBLE, | ||
COLUMN_TYPE_FLOAT, | ||
COLUMN_TYPE_VARCHAR, | ||
COLUMN_TYPE_TEXT, | ||
COLUMN_TYPE_MEDIUMTEXT, | ||
COLUMN_TYPE_LONGTEXT, | ||
COLUMN_TYPE_BOOLEAN, | ||
COLUMN_TYPE_DATETIME, | ||
COLUMN_TYPE_DATE, | ||
COLUMN_TYPE_TIMESTAMP | ||
)); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.