ALTER VIEW, ALTER PROCEDURE scripts

This commit is contained in:
Jan Prochazka 2022-12-31 13:05:16 +01:00
parent e13808945c
commit 4d8e0d44d1
2 changed files with 27 additions and 0 deletions

View File

@ -191,6 +191,10 @@
label: 'SQL: CREATE VIEW',
scriptTemplate: 'CREATE OBJECT',
},
{
label: 'SQL: ALTER VIEW',
scriptTemplate: 'ALTER OBJECT',
},
{
label: 'SQL: CREATE TABLE',
scriptTemplate: 'CREATE TABLE',
@ -253,6 +257,10 @@
label: 'SQL: CREATE MATERIALIZED VIEW',
scriptTemplate: 'CREATE OBJECT',
},
{
label: 'SQL: ALTER MATERIALIZED VIEW',
scriptTemplate: 'ALTER OBJECT',
},
{
label: 'SQL: CREATE TABLE',
scriptTemplate: 'CREATE TABLE',
@ -290,6 +298,10 @@
label: 'SQL: CREATE PROCEDURE',
scriptTemplate: 'CREATE OBJECT',
},
{
label: 'SQL: ALTER PROCEDURE',
scriptTemplate: 'ALTER OBJECT',
},
{
label: 'SQL: EXECUTE',
scriptTemplate: 'EXECUTE PROCEDURE',
@ -316,6 +328,10 @@
label: 'SQL: CREATE FUNCTION',
scriptTemplate: 'CREATE OBJECT',
},
{
label: 'SQL: ALTER FUNCTION',
scriptTemplate: 'ALTER OBJECT',
},
{
label: 'SQL Generator: CREATE FUNCTION',
sqlGeneratorProps: {

View File

@ -36,6 +36,17 @@ export default async function applyScriptTemplate(scriptTemplate, extensions, pr
else return objectInfo.createSql;
}
}
if (scriptTemplate == 'ALTER OBJECT') {
const objectInfo = await getSqlObjectInfo(props);
if (objectInfo) {
const createSql =
objectInfo.requiresFormat && objectInfo.createSql
? sqlFormatter.format(objectInfo.createSql)
: objectInfo.createSql || '';
const alterPrefix = createSql.trimStart().startsWith('CREATE ') ? 'ALTER ' : 'alter ';
return createSql.replace(/^\s*create\s+/i, alterPrefix);
}
}
if (scriptTemplate == 'EXECUTE PROCEDURE') {
const procedureInfo = await getSqlObjectInfo(props);
const connection = await getConnectionInfo(props);