Skip to content

Commit 3540c53

Browse files
committed
add remove rule in databricks. clean up unused code like remove-functions rule
1 parent 489252d commit 3540c53

File tree

14 files changed

+48
-87
lines changed

14 files changed

+48
-87
lines changed

clouds/bigquery/modules/Makefile

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ include $(COMMON_DIR)/Makefile
3434

3535
.SILENT:
3636

37-
.PHONY: help lint build build-share deploy deploy-share test remove remove-functions remove-share clean
37+
.PHONY: help lint build build-share deploy deploy-share test remove remove-share clean
3838

3939
help:
40-
echo "Available targets: lint build deploy test remove remove-functions clean"
40+
echo "Available targets: lint build deploy test remove clean"
4141

4242
lint: venv3 $(NODE_MODULES_DEV)
4343
echo "Linting modules..."
@@ -101,11 +101,6 @@ remove: check
101101
GOOGLE_APPLICATION_CREDENTIALS=$(GOOGLE_APPLICATION_CREDENTIALS) \
102102
$(COMMON_DIR)/run-script.js $(COMMON_DIR)/DROP_FUNCTIONS.sql
103103

104-
remove-functions: check
105-
echo "Removing functions..."
106-
REPLACEMENTS=$(REPLACEMENTS)" "$(REPLACEMENTS_EXTRA) \
107-
GOOGLE_APPLICATION_CREDENTIALS=$(GOOGLE_APPLICATION_CREDENTIALS) \
108-
$(COMMON_DIR)/run-script.js $(COMMON_DIR)/DROP_FUNCTIONS.sql
109104

110105
clean:
111106
echo "Cleaning modules..."
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
----------------------------
2+
-- Copyright (C) 2025 CARTO
3+
----------------------------
4+
5+
CREATE OR REPLACE PROCEDURE @@DB_SCHEMA@@.DROP_FUNCTIONS()
6+
SQL SECURITY INVOKER
7+
BEGIN
8+
FOR record AS
9+
SELECT CONCAT('DROP ', routine_type, ' `', routine_catalog, '`.`', routine_schema, '`.`', routine_name,'`;') AS drop_command
10+
FROM @@DB_CATALOG@@.INFORMATION_SCHEMA.ROUTINES
11+
WHERE routine_schema = '@@DB_UNQUALIFIED_SCHEMA@@'
12+
DO
13+
EXECUTE IMMEDIATE record.drop_command;
14+
END FOR;
15+
END;
16+
17+
CALL @@DB_SCHEMA@@.DROP_FUNCTIONS();

clouds/databricks/common/Makefile

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,23 @@ ifdef catalog
1515
export DB_CATALOG = $(catalog)
1616
endif
1717

18+
export DB_CATALOG := \`$(DB_CATALOG)\`
19+
20+
ifeq ($(production),1)
21+
export DB_SCHEMA = $(DB_CATALOG).\`$(DB_SCHEMA_DEFAULT)\`
22+
else
23+
export DB_SCHEMA = $(DB_CATALOG).\`$(DB_PREFIX)$(DB_SCHEMA_DEFAULT)\`
24+
endif
25+
1826
ifeq ($(production),1)
19-
export DB_SCHEMA = \`$(DB_CATALOG)\`.\`$(DB_SCHEMA_DEFAULT)\`
27+
export DB_SCHEMA = $(DB_CATALOG).\`$(DB_SCHEMA_DEFAULT)\`
28+
export DB_UNQUALIFIED_SCHEMA = $(DB_SCHEMA_DEFAULT)
2029
else
21-
export DB_SCHEMA = \`$(DB_CATALOG)\`.\`$(DB_PREFIX)$(DB_SCHEMA_DEFAULT)\`
30+
export DB_SCHEMA = $(DB_CATALOG).\`$(DB_PREFIX)$(DB_SCHEMA_DEFAULT)\`
31+
export DB_UNQUALIFIED_SCHEMA = $(DB_PREFIX)$(DB_SCHEMA_DEFAULT)
2232
endif
2333
34+
2435
.SILENT:
2536
2637
.PHONY: check venv3 $(NODE_MODULES_DEV)

clouds/databricks/common/build_modules.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,10 @@ function apply_replacements (text) {
150150
return text;
151151
}
152152

153-
// if (argv.dropfirst) {
154-
// const header = fs.readFileSync(path.resolve(__dirname, 'DROP_FUNCTIONS.sql')).toString();
155-
// content = header + content;
156-
// }
153+
if (argv.dropfirst) {
154+
const header = fs.readFileSync(path.resolve(__dirname, 'DROP_FUNCTIONS.sql')).toString();
155+
content = header + content;
156+
}
157157

158158
const footer = fs.readFileSync(path.resolve(__dirname, 'VERSION.sql')).toString();
159159
content += footer;
@@ -162,4 +162,4 @@ content = apply_replacements(content);
162162

163163
// Write modules.sql file
164164
fs.writeFileSync(path.join(outputDir, 'modules.sql'), content);
165-
console.log(`Write ${outputDir}/modules.sql`);
165+
console.log(`Write ${outputDir}/modules.sql`);

clouds/databricks/common/run_script.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ def apply_replacements(text):
1616
if replacement:
1717
pattern = re.compile(f'@@{replacement}@@', re.MULTILINE)
1818
text = pattern.sub(os.environ.get(replacement, ''), text)
19+
# Add the missing backtick unescaping (like build_modules.js line 149)
20+
text = text.replace('\\`', '`')
1921
return text
2022

2123

clouds/databricks/modules/Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ else
1515
export DB_PACKAGE_VERSION ?= $(shell cat $(ROOT_DIR)/../version)-dev
1616
endif
1717

18-
REPLACEMENTS = "DB_SCHEMA DB_VERSION_FUNCTION DB_PACKAGE_VERSION"
18+
REPLACEMENTS = "DB_SCHEMA DB_CATALOG DB_UNQUALIFIED_SCHEMA DB_VERSION_FUNCTION DB_PACKAGE_VERSION"
1919

2020
include $(COMMON_DIR)/Makefile
2121

@@ -61,7 +61,8 @@ test: check venv3 $(NODE_MODULES_DEV)
6161

6262
remove: venv3
6363
echo "Removing modules..."
64-
$(VENV3_BIN)/python $(COMMON_DIR)/run_query.py "DROP SCHEMA IF EXISTS $(DB_SCHEMA) CASCADE;"
64+
REPLACEMENTS=$(REPLACEMENTS)" "$(REPLACEMENTS_EXTRA) \
65+
$(VENV3_BIN)/python $(COMMON_DIR)/run_script.py $(COMMON_DIR)/DROP_FUNCTIONS.sql
6566

6667
clean:
6768
echo "Cleaning modules..."

clouds/databricks/modules/doc/product/VERSION_CORE.md

Lines changed: 0 additions & 20 deletions
This file was deleted.

clouds/databricks/modules/doc/product/_INTRO.md

Lines changed: 0 additions & 6 deletions
This file was deleted.

clouds/databricks/modules/sql/product/VERSION.sql

Lines changed: 0 additions & 4 deletions
This file was deleted.

clouds/databricks/modules/test/product/__init__.py

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)