Skip to content

Instantly share code, notes, and snippets.

View schmidt-sebastian's full-sized avatar

Sebastian Schmidt schmidt-sebastian

  • San Francisco, CA
View GitHub Profile
@Test
public void testTransactionIsCanceledAfterServerUpdate()
throws InterruptedException, ExecutionException {
// This test reproduces https://github.com/firebase/firebase-admin-java/issues/178:
//
// If we run two transactions (one at "path/nested1" and one at "path"), the SDK did not
// correctly re-run the "path" transaction if it got an update from the server for
// "path/nested2". This caused the "path" transaction to succeed on the server
// (our hash included the update from the server), merging stale data.
final DatabaseReference ref = IntegrationTestUtils.getRandomNode(masterApp);
await firestore.doc('coll/doc').set({'date': FieldValue.serverTimestamp() });
const date : Date = firestore.doc('coll/doc').get().get('date');
await firestore.doc('coll/doc').set({'date': date });
/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@schmidt-sebastian
schmidt-sebastian / Cloud Function
Created October 17, 2018 20:36
Activity Log Sample with Firestore
const firestore = admin.firestore;
exports.activityLog = functions.firestore
.document('privacy/{uid}').onWrite(snap => {
const uid = context.params.uid;
const settings = snap.data();
settings['udpate_time'] =
admin.firestore.FieldValue.serverTimestamp();
match /activity_log/{uid} {
allow create: if request.auth.uid == uid;
allow update: if false;
allow delete: if false;
}
@schmidt-sebastian
schmidt-sebastian / Security Rule
Created October 17, 2018 20:40
Activity Log Sample with Firestore + Cloud Functions Trigger
match /activity_log/{uid} {
allow create: if request.auth.uid == uid;
allow update: if false;
allow delete: if false;
}
@schmidt-sebastian
schmidt-sebastian / Security Rule
Created October 28, 2018 16:29
Activity Log Sample with Firestore + Cloud Functions Trigger
match /activity_log/{uid} {
allow create: if request.auth.uid == uid;
allow update: if request.auth.uid == uid && resource == null;
allow delete: if false;
}
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os
import re
import sys
def needsTag(idx, lines):
idx = idx - 1 # Skip "public void foo()" line
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
private SQLiteDatabase db;
@Override
diff --git a/google-cloud-clients/google-cloud-firestore/src/test/java/com/google/cloud/firestore/FirestoreTest.java b/google-cloud-clients/google-cloud-firestore/src/test/java/com/google/cloud/firestore/FirestoreTest.java
index c27e47b2c33..0366f7a0730 100644
--- a/google-cloud-clients/google-cloud-firestore/src/test/java/com/google/cloud/firestore/FirestoreTest.java
+++ b/google-cloud-clients/google-cloud-firestore/src/test/java/com/google/cloud/firestore/FirestoreTest.java
@@ -18,8 +18,14 @@ package com.google.cloud.firestore;
import static com.google.cloud.firestore.LocalFirestoreHelper.SINGLE_FIELD_OBJECT;
import static com.google.cloud.firestore.LocalFirestoreHelper.SINGLE_FIELD_PROTO;
+import static com.google.cloud.firestore.LocalFirestoreHelper.SINGLE_FIELD_VALUE;
+import static com.google.cloud.firestore.LocalFirestoreHelper.UPDATE_PRECONDITION;