Skip to content

Commit 612ae8e

Browse files
committed
Merge branch 'master' of github.com:FirebasePrivate/firebase-tools
2 parents 9d79b3e + 2ea950c commit 612ae8e

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

lib/deploy/functions/release.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ module.exports = function(context, options, payload) {
2323

2424
function _fetchTriggerUrls(ops) {
2525
return gcp.cloudfunctions.list(projectId, GCP_REGION).then(function(functions) {
26-
var httpFunctions = _.chain(functions).filter({ gcsUrl: sourceUrl}).filter('httpsTrigger').value();
26+
var httpFunctions = _.chain(functions).filter({ sourceArchiveUrl: sourceUrl}).filter('httpsTrigger').value();
2727
_.forEach(httpFunctions, function(httpFunc) {
2828
_.chain(ops).find({ func: httpFunc.name }).assign({ triggerUrl: httpFunc.httpsTrigger.url}).value();
2929
});
@@ -173,6 +173,28 @@ module.exports = function(context, options, payload) {
173173
var functionInfo = _.find(functionsInfo, {'name': functionName});
174174
return _prepFunctionOp(functionInfo, functionName).then(function(functionTrigger) {
175175
utils.logBullet(chalk.bold.cyan('functions: ') + 'updating function ' + chalk.bold(functionName) + '...');
176+
var existingFunction = _.find(existingFunctions, function(func) {
177+
return func.name.match(new RegExp('/' + functionName + '$'));
178+
});
179+
var existingTriggerType = _.get(existingFunction, 'eventTrigger.eventType');
180+
var newTriggerType = _.get(functionTrigger, 'eventTrigger.eventType');
181+
var isNowDBTrigger = newTriggerType === 'providers/firebase.database/eventTypes/data.write';
182+
// Firebase Database triggers used to be an odd prototype that was really a pubsub trigger. GCF won't allow
183+
// us to change the trigger type of an existing trigger so we have to delete functions that were based on
184+
// the old prototype and create them as real database triggers.
185+
if (isNowDBTrigger && newTriggerType !== existingTriggerType) {
186+
return gcp.cloudfunctions.delete(projectId, GCP_REGION, functionName)
187+
.then(function(call) {
188+
return _pollOperations([call]);
189+
}).then(function() {
190+
return gcp.cloudfunctions.create(
191+
projectId,
192+
GCP_REGION,
193+
functionName,
194+
functionInfo.entryPoint,
195+
functionTrigger, sourceUrl);
196+
});
197+
}
176198
return gcp.cloudfunctions.update(projectId, GCP_REGION, functionName, functionInfo.entryPoint, functionTrigger, sourceUrl);
177199
});
178200
}).value();

0 commit comments

Comments
 (0)