Skip to content

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
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
<action id="NewModelsAction" class="com.magento.idea.magento2plugin.actions.generation.NewModelsAction" />
<action id="MagentoCreateADataModel" class="com.magento.idea.magento2plugin.actions.generation.NewDataModelAction" />
<action id="MagentoMessageQueue" class="com.magento.idea.magento2plugin.actions.generation.NewMessageQueueAction" />
<action id="NewDbSchema" class="com.magento.idea.magento2plugin.actions.generation.NewDbSchemaAction" />
<add-to-group group-id="NewGroup" anchor="last"/>
</group>

Expand Down Expand Up @@ -224,6 +225,7 @@
<internalFileTemplate name="Magento Resource Model Class"/>
<internalFileTemplate name="Magento Data Model"/>
<internalFileTemplate name="Magento Data Model Interface"/>
<internalFileTemplate name="Magento Module Declarative Schema XML"/>

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

Expand Down
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>
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>
1 change: 1 addition & 0 deletions resources/magento2/validation.properties
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ validator.mustNotBeEmptyShouldContainLettersOrNumbers=Must not be empty, should
validator.magentoRouteIdInvalid=The route id is invalid
validator.magentoAclResourceIdInvalid=The ACL resource id is invalid
validator.lowercaseCharacters={0} must contain lowercase characters only
validator.db.invalidTableNameLength=Table name must contain up to 64 characters only (inclusive)
validator.lowerSnakeCase=The {0} field must be of the lower snake case format
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;
}
}
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;
}
}
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();
}
}
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
));
}
}
Loading