Skip to content

Commit 0d39210

Browse files
author
Vitaliy
authored
Merge pull request #453 from bohdan-harniuk/309-add-declarative-schema-generation
309 add declarative schema generation
2 parents 4472c86 + 20a5a2d commit 0d39210

File tree

23 files changed

+1858
-3
lines changed

23 files changed

+1858
-3
lines changed

gradle-tasks/pmd/ruleset.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@
3737
</rule>
3838
<exclude-pattern>.*/resources/.*</exclude-pattern>
3939
<exclude-pattern>.*/testData/.*</exclude-pattern>
40-
<rule ref="category/java/multithreading.xml"/>
40+
<rule ref="category/java/multithreading.xml">
41+
<exclude name="UseConcurrentHashMap" />
42+
</rule>
4143
<rule ref="category/java/performance.xml"/>
4244
<rule ref="category/java/security.xml" />
4345
</ruleset>

resources/META-INF/plugin.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
<action id="NewModelsAction" class="com.magento.idea.magento2plugin.actions.generation.NewModelsAction" />
7171
<action id="MagentoCreateADataModel" class="com.magento.idea.magento2plugin.actions.generation.NewDataModelAction" />
7272
<action id="MagentoMessageQueue" class="com.magento.idea.magento2plugin.actions.generation.NewMessageQueueAction" />
73+
<action id="NewDbSchema" class="com.magento.idea.magento2plugin.actions.generation.NewDbSchemaAction" />
7374
<add-to-group group-id="NewGroup" anchor="last"/>
7475
</group>
7576

@@ -224,6 +225,7 @@
224225
<internalFileTemplate name="Magento Resource Model Class"/>
225226
<internalFileTemplate name="Magento Data Model"/>
226227
<internalFileTemplate name="Magento Data Model Interface"/>
228+
<internalFileTemplate name="Magento Module Declarative Schema XML"/>
227229

228230
<defaultLiveTemplates file="/liveTemplates/MagentoPWA.xml"/>
229231

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0"?>
2+
<schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd">
4+
</schema>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<!--
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
-->
7+
<html lang="en">
8+
<body>
9+
<font face="verdana" size="-1">
10+
<p>
11+
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.
12+
</p>
13+
<p>
14+
Read more about <a href="https://devdocs.magento.com/guides/v2.4/extension-dev-guide/declarative-schema/">Declarative Schema Overview</a>.
15+
</p>
16+
</font>
17+
</body>
18+
</html>

resources/magento2/validation.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,5 @@ validator.mustNotBeEmptyShouldContainLettersOrNumbers=Must not be empty, should
3333
validator.magentoRouteIdInvalid=The route id is invalid
3434
validator.magentoAclResourceIdInvalid=The ACL resource id is invalid
3535
validator.lowercaseCharacters={0} must contain lowercase characters only
36+
validator.db.invalidTableNameLength=Table name must contain up to 64 characters only (inclusive)
3637
validator.lowerSnakeCase=The {0} field must be of the lower snake case format
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
package com.magento.idea.magento2plugin.actions.generation;
7+
8+
import com.intellij.ide.IdeView;
9+
import com.intellij.openapi.actionSystem.AnAction;
10+
import com.intellij.openapi.actionSystem.AnActionEvent;
11+
import com.intellij.openapi.actionSystem.CommonDataKeys;
12+
import com.intellij.openapi.actionSystem.DataContext;
13+
import com.intellij.openapi.actionSystem.LangDataKeys;
14+
import com.intellij.openapi.project.Project;
15+
import com.intellij.psi.PsiDirectory;
16+
import com.magento.idea.magento2plugin.MagentoIcons;
17+
import com.magento.idea.magento2plugin.actions.generation.dialog.NewDbSchemaDialog;
18+
import org.jetbrains.annotations.NotNull;
19+
20+
public class NewDbSchemaAction extends AnAction {
21+
public static final String ACTION_NAME = "Declarative Schema XML";
22+
public static final String ACTION_DESCRIPTION = "Create a new declarative schema XML";
23+
24+
/**
25+
* Constructor.
26+
*/
27+
public NewDbSchemaAction() {
28+
super(ACTION_NAME, ACTION_DESCRIPTION, MagentoIcons.MODULE);
29+
}
30+
31+
@Override
32+
public void actionPerformed(final @NotNull AnActionEvent event) {
33+
final DataContext dataContext = event.getDataContext();
34+
final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
35+
if (view == null) {
36+
return;
37+
}
38+
39+
final Project project = CommonDataKeys.PROJECT.getData(dataContext);
40+
if (project == null) {
41+
return;
42+
}
43+
44+
final PsiDirectory directory = view.getOrChooseDirectory();
45+
if (directory == null) {
46+
return;
47+
}
48+
NewDbSchemaDialog.open(project, directory);
49+
}
50+
51+
@Override
52+
public boolean isDumbAware() {
53+
return false;
54+
}
55+
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
package com.magento.idea.magento2plugin.actions.generation.data;
7+
8+
import com.magento.idea.magento2plugin.magento.files.ModuleDbSchemaXml;
9+
import java.util.LinkedHashMap;
10+
import java.util.LinkedList;
11+
import java.util.List;
12+
import java.util.Map;
13+
14+
public class DbSchemaXmlData {
15+
private String tableName;
16+
private String tableResource;
17+
private String tableEngine;
18+
private String tableComment;
19+
private List<Map<String, String>> columns;
20+
21+
/**
22+
* Constructor.
23+
*
24+
* @param tableName String
25+
* @param tableResource String
26+
* @param tableEngine String
27+
* @param tableComment String
28+
* @param columns List
29+
*/
30+
public DbSchemaXmlData(
31+
final String tableName,
32+
final String tableResource,
33+
final String tableEngine,
34+
final String tableComment,
35+
final List<Map<String, String>> columns
36+
) {
37+
this.tableName = tableName;
38+
this.tableResource = tableResource;
39+
this.tableEngine = tableEngine;
40+
this.tableComment = tableComment;
41+
this.columns = columns;
42+
}
43+
44+
public String getTableName() {
45+
return tableName;
46+
}
47+
48+
public void setTableName(final String tableName) {
49+
this.tableName = tableName;
50+
}
51+
52+
public String getTableResource() {
53+
return tableResource;
54+
}
55+
56+
public void setTableResource(final String tableResource) {
57+
this.tableResource = tableResource;
58+
}
59+
60+
public String getTableEngine() {
61+
return tableEngine;
62+
}
63+
64+
public void setTableEngine(final String tableEngine) {
65+
this.tableEngine = tableEngine;
66+
}
67+
68+
public String getTableComment() {
69+
return tableComment;
70+
}
71+
72+
public void setTableComment(final String tableComment) {
73+
this.tableComment = tableComment;
74+
}
75+
76+
public List<Map<String, String>> getColumns() {
77+
return new LinkedList<>(columns);
78+
}
79+
80+
public void setColumns(final List<Map<String, String>> columns) {
81+
this.columns = columns;
82+
}
83+
84+
/**
85+
* Get table attributes values map.
86+
*
87+
* @return Map
88+
*/
89+
public Map<String, String> getTableAttributesMap() {
90+
final Map<String, String> tableAttributesData = new LinkedHashMap<>();
91+
tableAttributesData.put(ModuleDbSchemaXml.XML_ATTR_TABLE_NAME, getTableName());
92+
tableAttributesData.put(ModuleDbSchemaXml.XML_ATTR_TABLE_RESOURCE, getTableResource());
93+
tableAttributesData.put(ModuleDbSchemaXml.XML_ATTR_TABLE_ENGINE, getTableEngine());
94+
tableAttributesData.put(ModuleDbSchemaXml.XML_ATTR_TABLE_COMMENT, getTableComment());
95+
96+
return tableAttributesData;
97+
}
98+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
package com.magento.idea.magento2plugin.actions.generation.data.ui;
7+
8+
/**
9+
* Data Models for storing ComboBox UI component item data.
10+
*/
11+
public class ComboBoxItemData {
12+
private final String key;
13+
private final String text;
14+
15+
/**
16+
* Constructor.
17+
*
18+
* @param key String
19+
* @param text String
20+
*/
21+
public ComboBoxItemData(final String key, final String text) {
22+
this.key = key;
23+
this.text = text;
24+
}
25+
26+
/**
27+
* Get key.
28+
*
29+
* @return String
30+
*/
31+
public String getKey() {
32+
return key;
33+
}
34+
35+
/**
36+
* Get Text.
37+
*
38+
* @return String
39+
*/
40+
public String getText() {
41+
return text;
42+
}
43+
44+
@Override
45+
public String toString() {
46+
return this.getText();
47+
}
48+
}

0 commit comments

Comments
 (0)