Skip to content

Commit 35d0e0d

Browse files
309: Generation of base table xml
1 parent 3a43929 commit 35d0e0d

16 files changed

+1134
-30
lines changed

resources/META-INF/plugin.xml

+1
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@
225225
<internalFileTemplate name="Magento Resource Model Class"/>
226226
<internalFileTemplate name="Magento Data Model"/>
227227
<internalFileTemplate name="Magento Data Model Interface"/>
228+
<internalFileTemplate name="Magento Module Declarative Schema XML"/>
228229

229230
<defaultLiveTemplates file="/liveTemplates/MagentoPWA.xml"/>
230231

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>
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

+1
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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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.Map;
11+
12+
public class DbSchemaXmlData {
13+
private String tableName;
14+
private String tableResource;
15+
private String tableEngine;
16+
private String tableComment;
17+
18+
/**
19+
* Constructor.
20+
*
21+
* @param tableName String
22+
* @param tableResource String
23+
* @param tableEngine String
24+
* @param tableComment String
25+
*/
26+
public DbSchemaXmlData(
27+
final String tableName,
28+
final String tableResource,
29+
final String tableEngine,
30+
final String tableComment
31+
) {
32+
this.tableName = tableName;
33+
this.tableResource = tableResource;
34+
this.tableEngine = tableEngine;
35+
this.tableComment = tableComment;
36+
}
37+
38+
public String getTableName() {
39+
return tableName;
40+
}
41+
42+
public void setTableName(final String tableName) {
43+
this.tableName = tableName;
44+
}
45+
46+
public String getTableResource() {
47+
return tableResource;
48+
}
49+
50+
public void setTableResource(final String tableResource) {
51+
this.tableResource = tableResource;
52+
}
53+
54+
public String getTableEngine() {
55+
return tableEngine;
56+
}
57+
58+
public void setTableEngine(final String tableEngine) {
59+
this.tableEngine = tableEngine;
60+
}
61+
62+
public String getTableComment() {
63+
return tableComment;
64+
}
65+
66+
public void setTableComment(final String tableComment) {
67+
this.tableComment = tableComment;
68+
}
69+
70+
/**
71+
* Get table attributes values map.
72+
*
73+
* @return Map
74+
*/
75+
public Map<String, String> getTableAttributesMap() {
76+
final Map<String, String> tableAttributesData = new LinkedHashMap<>();
77+
tableAttributesData.put(ModuleDbSchemaXml.XML_ATTR_TABLE_NAME, getTableName());
78+
tableAttributesData.put(ModuleDbSchemaXml.XML_ATTR_TABLE_RESOURCE, getTableResource());
79+
tableAttributesData.put(ModuleDbSchemaXml.XML_ATTR_TABLE_ENGINE, getTableEngine());
80+
tableAttributesData.put(ModuleDbSchemaXml.XML_ATTR_TABLE_COMMENT, getTableComment());
81+
82+
return tableAttributesData;
83+
}
84+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
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 java.util.Arrays;
9+
import java.util.LinkedList;
10+
import java.util.List;
11+
12+
public final class DbSchemaXmlSourceData {
13+
// currently available engines
14+
public static final String TABLE_ENGINE_INNODB = "innodb";
15+
public static final String TABLE_ENGINE_MEMORY = "memory";
16+
// currently available resources
17+
public static final String TABLE_RESOURCE_DEFAULT = "default";
18+
public static final String TABLE_RESOURCE_CHECKOUT = "checkout";
19+
public static final String TABLE_RESOURCE_SALES = "sales";
20+
// available column types
21+
// binaries
22+
public static final String COLUMN_TYPE_BLOB = "blob";
23+
public static final String COLUMN_TYPE_MEDIUMBLOB = "mediumblob";
24+
public static final String COLUMN_TYPE_LONGBLOB = "longblob";
25+
public static final String COLUMN_TYPE_VARBINARY = "varbinary";
26+
// integers
27+
public static final String COLUMN_TYPE_TINYINT = "tinyint";
28+
public static final String COLUMN_TYPE_SMALLINT = "smallint";
29+
public static final String COLUMN_TYPE_INT = "int";
30+
public static final String COLUMN_TYPE_BIGINT = "bigint";
31+
// reals
32+
public static final String COLUMN_TYPE_DECIMAL = "decimal";
33+
public static final String COLUMN_TYPE_DOUBLE = "double";
34+
public static final String COLUMN_TYPE_FLOAT = "float";
35+
// text
36+
public static final String COLUMN_TYPE_VARCHAR = "varchar";
37+
public static final String COLUMN_TYPE_TEXT = "text";
38+
public static final String COLUMN_TYPE_MEDIUMTEXT = "mediumtext";
39+
public static final String COLUMN_TYPE_LONGTEXT = "longtext";
40+
// boolean
41+
public static final String COLUMN_TYPE_BOOLEAN = "boolean";
42+
43+
/**
44+
* Denying the possibility to initialize this class.
45+
*/
46+
private DbSchemaXmlSourceData() {}
47+
48+
/**
49+
* Get source list for available table engines.
50+
*
51+
* @return List
52+
*/
53+
public static List<String> getTableEngineSource() {
54+
return new LinkedList<>(Arrays.asList(
55+
DbSchemaXmlSourceData.TABLE_ENGINE_INNODB,
56+
DbSchemaXmlSourceData.TABLE_ENGINE_MEMORY)
57+
);
58+
}
59+
60+
/**
61+
* Get source list for available table resources.
62+
*
63+
* @return List
64+
*/
65+
public static List<String> getTableResourceSource() {
66+
return new LinkedList<>(Arrays.asList(
67+
TABLE_RESOURCE_DEFAULT,
68+
TABLE_RESOURCE_CHECKOUT,
69+
TABLE_RESOURCE_SALES
70+
));
71+
}
72+
73+
/**
74+
* Get source list for available column types.
75+
*
76+
* @return List
77+
*/
78+
public static List<String> getColumnTypes() {
79+
return new LinkedList<>(Arrays.asList(
80+
"",
81+
COLUMN_TYPE_BLOB,
82+
COLUMN_TYPE_MEDIUMBLOB,
83+
COLUMN_TYPE_LONGBLOB,
84+
COLUMN_TYPE_VARBINARY,
85+
COLUMN_TYPE_TINYINT,
86+
COLUMN_TYPE_SMALLINT,
87+
COLUMN_TYPE_INT,
88+
COLUMN_TYPE_BIGINT,
89+
COLUMN_TYPE_DECIMAL,
90+
COLUMN_TYPE_DOUBLE,
91+
COLUMN_TYPE_FLOAT,
92+
COLUMN_TYPE_VARCHAR,
93+
COLUMN_TYPE_TEXT,
94+
COLUMN_TYPE_MEDIUMTEXT,
95+
COLUMN_TYPE_LONGTEXT,
96+
COLUMN_TYPE_BOOLEAN
97+
));
98+
}
99+
}
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)