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 all 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
4 changes: 3 additions & 1 deletion gradle-tasks/pmd/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
</rule>
<exclude-pattern>.*/resources/.*</exclude-pattern>
<exclude-pattern>.*/testData/.*</exclude-pattern>
<rule ref="category/java/multithreading.xml"/>
<rule ref="category/java/multithreading.xml">
<exclude name="UseConcurrentHashMap" />
</rule>
<rule ref="category/java/performance.xml"/>
<rule ref="category/java/security.xml" />
</ruleset>
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<>();
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();
}
}
Loading