From 6fc66acb0aaef513f506ee4f92b3c7f1d8e95b25 Mon Sep 17 00:00:00 2001
From: Dane Strandboge <dstrandboge@influxdata.com>
Date: Tue, 1 Nov 2022 09:47:45 -0500
Subject: [PATCH] fix: do not require remoteOrgID in remote config/creation
 request (#23838)

---
 cmd/influxd/downgrade/downgrade.go            |  1 +
 cmd/influxd/launcher/replication_test.go      | 22 ++---
 go.mod                                        | 10 +--
 go.sum                                        | 41 ++++-----
 remote_connection.go                          | 28 +++----
 remotes/service_test.go                       |  3 +-
 remotes/transport/http_test.go                |  2 +-
 remotes/transport/middleware_kv_test.go       |  6 +-
 replication.go                                |  2 +-
 replications/internal/store_test.go           | 18 ++--
 replications/remotewrite/writer.go            | 12 ++-
 replications/service_test.go                  |  3 +-
 ...8_migrate_remotes_null_remote_org.down.sql | 84 +++++++++++++++++++
 ...008_migrate_remotes_null_remote_org.up.sql | 81 ++++++++++++++++++
 14 files changed, 251 insertions(+), 62 deletions(-)
 create mode 100644 sqlite/migrations/0008_migrate_remotes_null_remote_org.down.sql
 create mode 100644 sqlite/migrations/0008_migrate_remotes_null_remote_org.up.sql

diff --git a/cmd/influxd/downgrade/downgrade.go b/cmd/influxd/downgrade/downgrade.go
index e4dee456ffe..4e343f7c85b 100644
--- a/cmd/influxd/downgrade/downgrade.go
+++ b/cmd/influxd/downgrade/downgrade.go
@@ -37,6 +37,7 @@ var downgradeMigrationTargets = map[string]migrationTarget{
 	"2.0": {kvMigration: 15, sqlMigration: 0},
 	"2.1": {kvMigration: 18, sqlMigration: 3},
 	"2.3": {kvMigration: 20, sqlMigration: 5},
+	"2.4": {kvMigration: 20, sqlMigration: 7},
 }
 
 func NewCommand(ctx context.Context, v *viper.Viper) (*cobra.Command, error) {
diff --git a/cmd/influxd/launcher/replication_test.go b/cmd/influxd/launcher/replication_test.go
index 58da3facba9..2a46c82fa43 100644
--- a/cmd/influxd/launcher/replication_test.go
+++ b/cmd/influxd/launcher/replication_test.go
@@ -33,7 +33,7 @@ func TestValidateReplication_Valid(t *testing.T) {
 			OrgID:            l.Org.ID.String(),
 			RemoteURL:        l.URL().String(),
 			RemoteAPIToken:   l.Auth.Token,
-			RemoteOrgID:      l.Org.ID.String(),
+			RemoteOrgID:      api.PtrString(l.Org.ID.String()),
 			AllowInsecureTLS: false,
 		}).Execute()
 	require.NoError(t, err)
@@ -44,7 +44,7 @@ func TestValidateReplication_Valid(t *testing.T) {
 		OrgID:             l.Org.ID.String(),
 		RemoteID:          remote.Id,
 		LocalBucketID:     l.Bucket.ID.String(),
-		RemoteBucketID:    l.Bucket.ID.String(),
+		RemoteBucketID:    api.PtrString(l.Bucket.ID.String()),
 		MaxQueueSizeBytes: influxdb.DefaultReplicationMaxQueueSizeBytes,
 	}
 	_, err = client.ReplicationsApi.PostReplication(ctx).ReplicationCreationRequest(createReq).Validate(true).Execute()
@@ -97,7 +97,7 @@ func TestValidateReplication_Invalid(t *testing.T) {
 			OrgID:            l.Org.ID.String(),
 			RemoteURL:        l.URL().String(),
 			RemoteAPIToken:   "foo",
-			RemoteOrgID:      l.Org.ID.String(),
+			RemoteOrgID:      api.PtrString(l.Org.ID.String()),
 			AllowInsecureTLS: false,
 		}).Execute()
 	require.NoError(t, err)
@@ -109,7 +109,7 @@ func TestValidateReplication_Invalid(t *testing.T) {
 		OrgID:             l.Org.ID.String(),
 		RemoteID:          remote.Id,
 		LocalBucketID:     l.Bucket.ID.String(),
-		RemoteBucketID:    l.Bucket.ID.String(),
+		RemoteBucketID:    api.PtrString(l.Bucket.ID.String()),
 		MaxQueueSizeBytes: influxdb.DefaultReplicationMaxQueueSizeBytes,
 	}
 	_, err = client.ReplicationsApi.PostReplication(ctx).ReplicationCreationRequest(createReq).Validate(true).Execute()
@@ -233,7 +233,7 @@ csv.from(csv: csvData) |> to(bucket: %q)
 			OrgID:            l.Org.ID.String(),
 			RemoteURL:        proxy.URL,
 			RemoteAPIToken:   l.Auth.Token,
-			RemoteOrgID:      l.Org.ID.String(),
+			RemoteOrgID:      api.PtrString(l.Org.ID.String()),
 			AllowInsecureTLS: false,
 		}).Execute()
 	require.NoError(t, err)
@@ -257,7 +257,7 @@ csv.from(csv: csvData) |> to(bucket: %q)
 		OrgID:             l.Org.ID.String(),
 		RemoteID:          remote.Id,
 		LocalBucketID:     l.Bucket.ID.String(),
-		RemoteBucketID:    remote1Bucket.ID.String(),
+		RemoteBucketID:    api.PtrString(remote1Bucket.ID.String()),
 		MaxQueueSizeBytes: influxdb.DefaultReplicationMaxQueueSizeBytes,
 		MaxAgeSeconds:     influxdb.DefaultReplicationMaxAge,
 	}
@@ -284,7 +284,7 @@ csv.from(csv: csvData) |> to(bucket: %q)
 		OrgID:             l.Org.ID.String(),
 		RemoteID:          remote.Id,
 		LocalBucketID:     l.Bucket.ID.String(),
-		RemoteBucketID:    remote2Bucket.ID.String(),
+		RemoteBucketID:    api.PtrString(remote2Bucket.ID.String()),
 		MaxQueueSizeBytes: influxdb.DefaultReplicationMaxQueueSizeBytes,
 		MaxAgeSeconds:     influxdb.DefaultReplicationMaxAge,
 	}
@@ -378,7 +378,7 @@ func TestReplicationStreamEndToEndRemoteFailures(t *testing.T) {
 			OrgID:            l.Org.ID.String(),
 			RemoteURL:        proxy.URL,
 			RemoteAPIToken:   l.Auth.Token,
-			RemoteOrgID:      l.Org.ID.String(),
+			RemoteOrgID:      api.PtrString(l.Org.ID.String()),
 			AllowInsecureTLS: false,
 		}).Execute()
 	require.NoError(t, err)
@@ -397,7 +397,7 @@ func TestReplicationStreamEndToEndRemoteFailures(t *testing.T) {
 		OrgID:             l.Org.ID.String(),
 		RemoteID:          remote.Id,
 		LocalBucketID:     l.Bucket.ID.String(),
-		RemoteBucketID:    remoteBucket.ID.String(),
+		RemoteBucketID:    api.PtrString(remoteBucket.ID.String()),
 		MaxQueueSizeBytes: influxdb.DefaultReplicationMaxQueueSizeBytes,
 		MaxAgeSeconds:     influxdb.DefaultReplicationMaxAge,
 	}
@@ -434,7 +434,7 @@ func TestReplicationsLocalWriteAndShutdownBlocking(t *testing.T) {
 			OrgID:            l.Org.ID.String(),
 			RemoteURL:        svr.URL,
 			RemoteAPIToken:   "foo",
-			RemoteOrgID:      l.Org.ID.String(),
+			RemoteOrgID:      api.PtrString(l.Org.ID.String()),
 			AllowInsecureTLS: false,
 		}).Execute()
 	require.NoError(t, err)
@@ -444,7 +444,7 @@ func TestReplicationsLocalWriteAndShutdownBlocking(t *testing.T) {
 		OrgID:             l.Org.ID.String(),
 		RemoteID:          remote.Id,
 		LocalBucketID:     l.Bucket.ID.String(),
-		RemoteBucketID:    l.Bucket.ID.String(),
+		RemoteBucketID:    api.PtrString(l.Bucket.ID.String()),
 		MaxQueueSizeBytes: influxdb.DefaultReplicationMaxQueueSizeBytes,
 	}
 
diff --git a/go.mod b/go.mod
index 04972aaa5b1..cde811c878b 100644
--- a/go.mod
+++ b/go.mod
@@ -31,7 +31,7 @@ require (
 	github.com/influxdata/cron v0.0.0-20201006132531-4bb0a200dcbe
 	github.com/influxdata/flux v0.188.1
 	github.com/influxdata/httprouter v1.3.1-0.20191122104820-ee83e2772f69
-	github.com/influxdata/influx-cli/v2 v2.2.1-0.20220318222112-88ba3464cd07
+	github.com/influxdata/influx-cli/v2 v2.2.1-0.20221028161653-3285a03e9e28
 	github.com/influxdata/influxql v1.1.1-0.20211004132434-7e7d61973256
 	github.com/influxdata/line-protocol v0.0.0-20200327222509-2487e7298839
 	github.com/influxdata/pkg-config v0.2.11
@@ -65,7 +65,7 @@ require (
 	go.uber.org/zap v1.16.0
 	golang.org/x/crypto v0.0.0-20220331220935-ae2d96664a29
 	golang.org/x/sync v0.0.0-20220513210516-0976fa681c29
-	golang.org/x/sys v0.0.0-20220412211240-33da011f77ad
+	golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a
 	golang.org/x/text v0.3.7
 	golang.org/x/time v0.0.0-20210220033141-f8bda1e9f3ba
 	golang.org/x/tools v0.1.11-0.20220316014157-77aa08bb151a
@@ -79,7 +79,7 @@ require (
 	cloud.google.com/go v0.82.0 // indirect
 	cloud.google.com/go/bigquery v1.8.0 // indirect
 	cloud.google.com/go/bigtable v1.10.1 // indirect
-	github.com/AlecAivazis/survey/v2 v2.2.9 // indirect
+	github.com/AlecAivazis/survey/v2 v2.3.4 // indirect
 	github.com/Azure/azure-pipeline-go v0.2.3 // indirect
 	github.com/Azure/azure-storage-blob-go v0.14.0 // indirect
 	github.com/Azure/go-autorest v14.2.0+incompatible // indirect
@@ -163,7 +163,7 @@ require (
 	github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 // indirect
 	github.com/lib/pq v1.2.0 // indirect
 	github.com/magiconair/properties v1.8.1 // indirect
-	github.com/mattn/go-colorable v0.1.9 // indirect
+	github.com/mattn/go-colorable v0.1.12 // indirect
 	github.com/mattn/go-ieproxy v0.0.1 // indirect
 	github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b // indirect
 	github.com/mitchellh/go-homedir v1.1.0 // indirect
@@ -203,7 +203,7 @@ require (
 	golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 // indirect
 	golang.org/x/net v0.0.0-20220401154927-543a649e0bdd // indirect
 	golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c // indirect
-	golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
+	golang.org/x/term v0.0.0-20220526004731-065cf7ba2467 // indirect
 	golang.org/x/xerrors v0.0.0-20220411194840-2f41105eb62f // indirect
 	gonum.org/v1/gonum v0.11.0 // indirect
 	google.golang.org/api v0.47.0 // indirect
diff --git a/go.sum b/go.sum
index 82fb4673cc9..3f186e9d2d4 100644
--- a/go.sum
+++ b/go.sum
@@ -44,8 +44,8 @@ cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9
 dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
 dmitri.shuralyov.com/gpu/mtl v0.0.0-20201218220906-28db891af037/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
 gioui.org v0.0.0-20210308172011-57750fc8a0a6/go.mod h1:RSH6KIUZ0p2xy5zHDxgAM4zumjgTw83q2ge/PI+yyw8=
-github.com/AlecAivazis/survey/v2 v2.2.9 h1:LWvJtUswz/W9/zVVXELrmlvdwWcKE60ZAw0FWV9vssk=
-github.com/AlecAivazis/survey/v2 v2.2.9/go.mod h1:9DYvHgXtiXm6nCn+jXnOXLKbH+Yo9u8fAS/SduGdoPk=
+github.com/AlecAivazis/survey/v2 v2.3.4 h1:pchTU9rsLUSvWEl2Aq9Pv3k0IE2fkqtGxazskAMd9Ng=
+github.com/AlecAivazis/survey/v2 v2.3.4/go.mod h1:hrV6Y/kQCLhIZXGcriDCUBtB3wnN7156gMXJ3+b23xM=
 github.com/Azure/azure-pipeline-go v0.2.3 h1:7U9HBg1JFK3jHl5qmo4CTZKFTVgMwdFHMVtCdfBE21U=
 github.com/Azure/azure-pipeline-go v0.2.3/go.mod h1:x841ezTBIMG6O3lAcl8ATHnsOPVl2bqk7S3ta6S6u4k=
 github.com/Azure/azure-storage-blob-go v0.14.0 h1:1BCg74AmVdYwO3dlKwtFU1V0wU2PZdREkXvAmZJRUlM=
@@ -90,8 +90,8 @@ github.com/Microsoft/go-winio v0.4.11 h1:zoIOcVf0xPN1tnMVbTtEdI+P8OofVk3NObnwOQ6
 github.com/Microsoft/go-winio v0.4.11/go.mod h1:VhR8bwka0BXejwEJY73c50VrPtXAaKcyvVC4A4RozmA=
 github.com/NYTimes/gziphandler v1.0.1 h1:iLrQrdwjDd52kHDA5op2UBJFjmOb9g+7scBan4RN8F0=
 github.com/NYTimes/gziphandler v1.0.1/go.mod h1:3wb06e3pkSAbeQ52E9H9iFoQsEEwGN64994WTCIhntQ=
-github.com/Netflix/go-expect v0.0.0-20180615182759-c93bf25de8e8 h1:xzYJEypr/85nBpB11F9br+3HUrpgb+fcm5iADzXXYEw=
-github.com/Netflix/go-expect v0.0.0-20180615182759-c93bf25de8e8/go.mod h1:oX5x61PbNXchhh0oikYAH+4Pcfw5LKv21+Jnpr6r6Pc=
+github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2 h1:+vx7roKuyA63nhn5WAunQHLTznkw5W8b1Xc0dNjp83s=
+github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2/go.mod h1:HBCaDeC1lPdgDeDbhX8XFpy1jqjK0IBG8W5K+xYqA0w=
 github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5/go.mod h1:lmUJ/7eu/Q8D7ML55dXQrVaamCz2vxCfdQBasLZfHKk=
 github.com/OneOfOne/xxhash v1.2.2 h1:KMrpdQIwFcEqXDklaen+P1axHaj9BSKzvpUUfnHldSE=
 github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
@@ -215,6 +215,8 @@ github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:ma
 github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
 github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
 github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
+github.com/creack/pty v1.1.17 h1:QeVUsEDNrLBW4tMgZHvxy18sKtr6VI492kBhUfhDJNI=
+github.com/creack/pty v1.1.17/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4=
 github.com/cyberdelia/templates v0.0.0-20141128023046-ca7fffd4298c/go.mod h1:GyV+0YP4qX0UQ7r2MoYZ+AvYDp12OF5yg4q8rGnyNh4=
 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
 github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
@@ -488,8 +490,8 @@ github.com/hashicorp/vault/sdk v0.1.8 h1:pfF3KwA1yPlfpmcumNsFM4uo91WMasX5gTuIkIt
 github.com/hashicorp/vault/sdk v0.1.8/go.mod h1:tHZfc6St71twLizWNHvnnbiGFo1aq0eD2jGPLtP8kAU=
 github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM=
 github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM=
-github.com/hinshun/vt10x v0.0.0-20180616224451-1954e6464174 h1:WlZsjVhE8Af9IcZDGgJGQpNflI3+MJSBhsgT5PCtzBQ=
-github.com/hinshun/vt10x v0.0.0-20180616224451-1954e6464174/go.mod h1:DqJ97dSdRW1W22yXSB90986pcOyQ7r45iio1KN2ez1A=
+github.com/hinshun/vt10x v0.0.0-20220119200601-820417d04eec h1:qv2VnGeEQHchGaZ/u7lxST/RaJw+cv273q79D81Xbog=
+github.com/hinshun/vt10x v0.0.0-20220119200601-820417d04eec/go.mod h1:Q48J4R4DvxnHolD5P8pOtXigYlRuPLGl6moFx3ulM68=
 github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
 github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
 github.com/huandu/xstrings v1.0.0 h1:pO2K/gKgKaat5LdpAhxhluX2GPQMaI3W5FUz/I/UnWk=
@@ -510,8 +512,8 @@ github.com/influxdata/gosnowflake v1.6.9 h1:BhE39Mmh8bC+Rvd4QQsP2gHypfeYIH1wqW1A
 github.com/influxdata/gosnowflake v1.6.9/go.mod h1:9W/BvCXOKx2gJtQ+jdi1Vudev9t9/UDOEHnlJZ/y1nU=
 github.com/influxdata/httprouter v1.3.1-0.20191122104820-ee83e2772f69 h1:WQsmW0fXO4ZE/lFGIE84G6rIV5SJN3P3sjIXAP1a8eU=
 github.com/influxdata/httprouter v1.3.1-0.20191122104820-ee83e2772f69/go.mod h1:pwymjR6SrP3gD3pRj9RJwdl1j5s3doEEV8gS4X9qSzA=
-github.com/influxdata/influx-cli/v2 v2.2.1-0.20220318222112-88ba3464cd07 h1:qfj5kTFYg5KhePA0A5BzFV6zxW0yLYF5K0O7t3drqn8=
-github.com/influxdata/influx-cli/v2 v2.2.1-0.20220318222112-88ba3464cd07/go.mod h1:p1X8Ga67SzLC35qmwvTCmWXdpZOTHSWWMXJ0zwRTW50=
+github.com/influxdata/influx-cli/v2 v2.2.1-0.20221028161653-3285a03e9e28 h1:brESt4mwZknEUuwrYcGSG6JqjTKC5M+qVKgL73ondFg=
+github.com/influxdata/influx-cli/v2 v2.2.1-0.20221028161653-3285a03e9e28/go.mod h1:rvb2oIMqPs+O9gL6r0kqJ2X0tbQ8WRRtteeWfCqdhZU=
 github.com/influxdata/influxdb-client-go/v2 v2.3.1-0.20210518120617-5d1fff431040 h1:MBLCfcSsUyFPDJp6T7EoHp/Ph3Jkrm4EuUKLD2rUWHg=
 github.com/influxdata/influxdb-client-go/v2 v2.3.1-0.20210518120617-5d1fff431040/go.mod h1:vLNHdxTJkIf2mSLvGrpj8TCcISApPoXkaxP8g9uRlW8=
 github.com/influxdata/influxdb-iox-client-go v1.0.0-beta.1 h1:zDmAiE2o3Y/YZinI6CENzgQueJDuibUB9TWOZC5zCq0=
@@ -577,8 +579,6 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN
 github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
 github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
 github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
-github.com/kr/pty v1.1.4 h1:5Myjjh3JY/NaAi4IsUbHADytDyl1VE1Y9PXDlL+P/VQ=
-github.com/kr/pty v1.1.4/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
 github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
 github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
 github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
@@ -604,8 +604,9 @@ github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVc
 github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
 github.com/mattn/go-colorable v0.1.7/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
 github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
-github.com/mattn/go-colorable v0.1.9 h1:sqDoxXbdeALODt0DAeJCVp38ps9ZogZEAXjus69YV3U=
 github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
+github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40=
+github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
 github.com/mattn/go-ieproxy v0.0.1 h1:qiyop7gCflfhwCzGyeT0gro3sF9AIg9HU98JORTkqfI=
 github.com/mattn/go-ieproxy v0.0.1/go.mod h1:pYabZ6IHcRpFh7vIaLfK7rdcWgFEb3SFJ6/gNWuh88E=
 github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
@@ -617,11 +618,11 @@ github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Ky
 github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
 github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
 github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
-github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
+github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU=
 github.com/mattn/go-sqlite3 v1.14.6/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
 github.com/mattn/go-sqlite3 v1.14.7 h1:fxWBnXkxfM6sRiuH3bqJ4CfzZojMOLVc0UTsTglEghA=
 github.com/mattn/go-sqlite3 v1.14.7/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
-github.com/mattn/go-tty v0.0.0-20180907095812-13ff1204f104 h1:d8RFOZ2IiFtFWBcKEHAFYJcPTf0wY5q0exFNJZVWa1U=
+github.com/mattn/go-tty v0.0.4 h1:NVikla9X8MN0SQAqCYzpGyXv0jY7MNl3HOWD2dkle7E=
 github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=
 github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
 github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b h1:j7+1HpAFS1zy5+Q4qx1fWh90gTKwiN4QCGoY9TWyyO4=
@@ -713,7 +714,7 @@ github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
 github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
 github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
 github.com/pkg/profile v1.2.1/go.mod h1:hJw3o1OdXxsrSjjVksARp5W95eeEaEfptyVZyv6JUPA=
-github.com/pkg/term v0.0.0-20180730021639-bffc007b7fd5 h1:tFwafIEMf0B7NlcxV/zJ6leBIa81D3hgGSgsE5hCkOQ=
+github.com/pkg/term v1.2.0-beta.2 h1:L3y/h2jkuBVFdWiJvNfYfKmzcCnILw7mJWm2JQuMppw=
 github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
 github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
 github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
@@ -749,6 +750,7 @@ github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40T
 github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
 github.com/retailnext/hllpp v1.0.1-0.20180308014038-101a6d2f8b52 h1:RnWNS9Hlm8BIkjr6wx8li5abe0fr73jljLycdfemTp0=
 github.com/retailnext/hllpp v1.0.1-0.20180308014038-101a6d2f8b52/go.mod h1:RDpi1RftBQPUCDRw6SmxeaREsAaRKnOclghuzp/WRzc=
+github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
 github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
 github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
 github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
@@ -808,7 +810,6 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
 github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
 github.com/stretchr/objx v0.4.0 h1:M2gUjqZET1qApGOWNSnZ49BAIMX4F/1plDv3+l31EJ4=
 github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
-github.com/stretchr/testify v1.2.1/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
 github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
 github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
 github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
@@ -909,7 +910,6 @@ golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnf
 golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
 golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
 golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
-golang.org/x/crypto v0.0.0-20190530122614-20be4c3c3ed5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
 golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
 golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
 golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
@@ -1077,7 +1077,6 @@ golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7w
 golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
-golang.org/x/sys v0.0.0-20190530182044-ad28b68e88f1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
@@ -1128,15 +1127,19 @@ golang.org/x/sys v0.0.0-20210601080250-7ecdf8ef093b/go.mod h1:oPkhp1MJrh7nUepCBc
 golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 golang.org/x/sys v0.0.0-20210616045830-e2b7044e8c71/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 golang.org/x/sys v0.0.0-20211117180635-dee7805ff2e1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
-golang.org/x/sys v0.0.0-20220412211240-33da011f77ad h1:ntjMns5wyP/fN65tdBD4g8J5w8n015+iIIs9rtjXkY0=
 golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a h1:dGzPydgVsqGcTRVwiLJ1jVbufYwmzD3LfVPLKsKg+0k=
+golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
 golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
-golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 h1:JGgROgKl9N8DuW20oFS5gxc+lE67/N3FcwmBPMe7ArY=
+golang.org/x/term v0.0.0-20210503060354-a79de5458b56/go.mod h1:tfny5GFUkzUvx4ps4ajbZsCe5lw1metzhBm9T3x7oIY=
 golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
+golang.org/x/term v0.0.0-20220526004731-065cf7ba2467 h1:CBpWXWQpIRjzmkkA+M7q9Fqnwd2mZr3AFqexg8YTfoM=
+golang.org/x/term v0.0.0-20220526004731-065cf7ba2467/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
 golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
 golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
 golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
diff --git a/remote_connection.go b/remote_connection.go
index 331efb6f502..7d0a3e70514 100644
--- a/remote_connection.go
+++ b/remote_connection.go
@@ -7,13 +7,13 @@ import (
 // RemoteConnection contains all info about a remote InfluxDB instance that should be returned to users.
 // Note that the auth token used by the request is *not* included here.
 type RemoteConnection struct {
-	ID               platform.ID `json:"id" db:"id"`
-	OrgID            platform.ID `json:"orgID" db:"org_id"`
-	Name             string      `json:"name" db:"name"`
-	Description      *string     `json:"description,omitempty" db:"description"`
-	RemoteURL        string      `json:"remoteURL" db:"remote_url"`
-	RemoteOrgID      platform.ID `json:"remoteOrgID" db:"remote_org_id"`
-	AllowInsecureTLS bool        `json:"allowInsecureTLS" db:"allow_insecure_tls"`
+	ID               platform.ID  `json:"id" db:"id"`
+	OrgID            platform.ID  `json:"orgID" db:"org_id"`
+	Name             string       `json:"name" db:"name"`
+	Description      *string      `json:"description,omitempty" db:"description"`
+	RemoteURL        string       `json:"remoteURL" db:"remote_url"`
+	RemoteOrgID      *platform.ID `json:"remoteOrgID" db:"remote_org_id"`
+	AllowInsecureTLS bool         `json:"allowInsecureTLS" db:"allow_insecure_tls"`
 }
 
 // RemoteConnectionListFilter is a selection filter for listing remote InfluxDB instances.
@@ -31,13 +31,13 @@ type RemoteConnections struct {
 // CreateRemoteConnectionRequest contains all info needed to establish a new connection to a remote
 // InfluxDB instance.
 type CreateRemoteConnectionRequest struct {
-	OrgID            platform.ID `json:"orgID"`
-	Name             string      `json:"name"`
-	Description      *string     `json:"description,omitempty"`
-	RemoteURL        string      `json:"remoteURL"`
-	RemoteToken      string      `json:"remoteAPIToken"`
-	RemoteOrgID      platform.ID `json:"remoteOrgID"`
-	AllowInsecureTLS bool        `json:"allowInsecureTLS"`
+	OrgID            platform.ID  `json:"orgID"`
+	Name             string       `json:"name"`
+	Description      *string      `json:"description,omitempty"`
+	RemoteURL        string       `json:"remoteURL"`
+	RemoteToken      string       `json:"remoteAPIToken"`
+	RemoteOrgID      *platform.ID `json:"remoteOrgID"`
+	AllowInsecureTLS bool         `json:"allowInsecureTLS"`
 }
 
 // UpdateRemoteConnectionRequest contains a partial update to existing info about a remote InfluxDB instance.
diff --git a/remotes/service_test.go b/remotes/service_test.go
index 0ff55f5b365..4f254792549 100644
--- a/remotes/service_test.go
+++ b/remotes/service_test.go
@@ -17,13 +17,14 @@ var (
 	ctx        = context.Background()
 	initID     = platform.ID(1)
 	desc       = "testing testing"
+	remoteID   = platform.ID(20)
 	connection = influxdb.RemoteConnection{
 		ID:               initID,
 		OrgID:            platform.ID(10),
 		Name:             "test",
 		Description:      &desc,
 		RemoteURL:        "https://influxdb.cloud",
-		RemoteOrgID:      platform.ID(20),
+		RemoteOrgID:      &remoteID,
 		AllowInsecureTLS: true,
 	}
 	fakeToken = "abcdefghijklmnop"
diff --git a/remotes/transport/http_test.go b/remotes/transport/http_test.go
index 9d3152d1c32..cf14c5a4467 100644
--- a/remotes/transport/http_test.go
+++ b/remotes/transport/http_test.go
@@ -31,7 +31,7 @@ var (
 		OrgID:            *orgID,
 		Name:             "example",
 		RemoteURL:        "https://influxdb.cloud",
-		RemoteOrgID:      *remoteOrgID,
+		RemoteOrgID:      remoteOrgID,
 		AllowInsecureTLS: true,
 	}
 )
diff --git a/remotes/transport/middleware_kv_test.go b/remotes/transport/middleware_kv_test.go
index d9afedc7c7d..16a3f8d7231 100644
--- a/remotes/transport/middleware_kv_test.go
+++ b/remotes/transport/middleware_kv_test.go
@@ -58,12 +58,13 @@ func TestRemoteCreateKVUpdate(t *testing.T) {
 	require.NoError(t, kvMigrator.Up(context.Background()))
 
 	ctx := context.Background()
+	remoteID := platform.ID(2)
 	req := influxdb.CreateRemoteConnectionRequest{
 		OrgID:       platform.ID(1),
 		Name:        "test1",
 		RemoteURL:   "cloud2.influxdata.com",
 		RemoteToken: "testtoken",
-		RemoteOrgID: platform.ID(2),
+		RemoteOrgID: &remoteID,
 	}
 
 	remoteConnction := influxdb.RemoteConnection{
@@ -101,12 +102,13 @@ func TestRemoteDeleteKVUpdate(t *testing.T) {
 	require.NoError(t, err)
 	require.NoError(t, kvMigrator.Up(ctx))
 
+	remoteID := platform.ID(2)
 	req := influxdb.CreateRemoteConnectionRequest{
 		OrgID:       platform.ID(1),
 		Name:        "test1",
 		RemoteURL:   "cloud2.influxdata.com",
 		RemoteToken: "testtoken",
-		RemoteOrgID: platform.ID(2),
+		RemoteOrgID: &remoteID,
 	}
 	req2 := req
 	req2.Name = "test2"
diff --git a/replication.go b/replication.go
index 9f625f05372..a006e0c6cb9 100644
--- a/replication.go
+++ b/replication.go
@@ -109,7 +109,7 @@ func (r *UpdateReplicationRequest) OK() error {
 type ReplicationHTTPConfig struct {
 	RemoteURL            string       `db:"remote_url"`
 	RemoteToken          string       `db:"remote_api_token"`
-	RemoteOrgID          platform.ID  `db:"remote_org_id"`
+	RemoteOrgID          *platform.ID `db:"remote_org_id"`
 	AllowInsecureTLS     bool         `db:"allow_insecure_tls"`
 	RemoteBucketID       *platform.ID `db:"remote_bucket_id"`
 	RemoteBucketName     string       `db:"remote_bucket_name"`
diff --git a/replications/internal/store_test.go b/replications/internal/store_test.go
index 9e6293f78c9..91d0ea4bc03 100644
--- a/replications/internal/store_test.go
+++ b/replications/internal/store_test.go
@@ -4,6 +4,7 @@ import (
 	"context"
 	"fmt"
 	"net/http"
+	"sort"
 	"testing"
 
 	sq "github.com/Masterminds/squirrel"
@@ -44,14 +45,13 @@ var (
 	httpConfig = influxdb.ReplicationHTTPConfig{
 		RemoteURL:        fmt.Sprintf("http://%s.cloud", replication.RemoteID),
 		RemoteToken:      replication.RemoteID.String(),
-		RemoteOrgID:      platform.ID(888888),
+		RemoteOrgID:      idPointer(888888),
 		AllowInsecureTLS: true,
 		RemoteBucketID:   replication.RemoteBucketID,
 	}
-	newRemoteID  = platform.ID(200)
 	newQueueSize = influxdb.MinReplicationMaxQueueSizeBytes
 	updateReq    = influxdb.UpdateReplicationRequest{
-		RemoteID:             &newRemoteID,
+		RemoteID:             idPointer(200),
 		MaxQueueSizeBytes:    &newQueueSize,
 		DropNonRetryableData: boolPointer(true),
 	}
@@ -393,6 +393,14 @@ func TestListReplications(t *testing.T) {
 
 		listed, err := testStore.ListReplications(ctx, influxdb.ReplicationListFilter{OrgID: createReq.OrgID})
 		require.NoError(t, err)
+
+		// The order from sqlite is not the same, so for simplicity we sort both lists before comparing.
+		sort.Slice(allRepls, func(i int, j int) bool {
+			return allRepls[i].ID < allRepls[j].ID
+		})
+		sort.Slice(listed.Replications, func(i int, j int) bool {
+			return listed.Replications[i].ID < listed.Replications[j].ID
+		})
 		require.Equal(t, influxdb.Replications{Replications: allRepls}, *listed)
 	})
 
@@ -496,7 +504,7 @@ func TestMigrateDownFromReplicationsWithName(t *testing.T) {
 
 	logger := zaptest.NewLogger(t)
 	sqliteMigrator := sqlite.NewMigrator(testStore.sqlStore, logger)
-	require.NoError(t, sqliteMigrator.Down(ctx, 6, migrations.AllDown))
+	require.NoError(t, sqliteMigrator.Down(ctx, 5, migrations.AllDown))
 
 	// Can't use ListReplications because it expects the `remote_bucket_name` column to be there in this version of influx.
 	q := sq.Select(
@@ -544,7 +552,7 @@ func TestPopulateRemoteHTTPConfig(t *testing.T) {
 	testStore, clean := newTestStore(t)
 	defer clean(t)
 
-	emptyConfig := &influxdb.ReplicationHTTPConfig{}
+	emptyConfig := &influxdb.ReplicationHTTPConfig{RemoteOrgID: idPointer(0)}
 
 	// Remote not found returns the appropriate error
 	target := &influxdb.ReplicationHTTPConfig{}
diff --git a/replications/remotewrite/writer.go b/replications/remotewrite/writer.go
index 11fd4fb3788..854d870b7ad 100644
--- a/replications/remotewrite/writer.go
+++ b/replications/remotewrite/writer.go
@@ -215,10 +215,18 @@ func PostWrite(ctx context.Context, config *influxdb.ReplicationHTTPConfig, data
 		bucket = config.RemoteBucketID.String()
 	}
 
+	var org string
+	if config.RemoteOrgID != nil {
+		org = config.RemoteOrgID.String()
+	} else {
+		// We need to provide something here for the write api to be happy
+		org = platform.InvalidID().String()
+	}
+
 	req := client.PostWrite(ctx).
-		Org(config.RemoteOrgID.String()).
 		Bucket(bucket).
-		Body(data)
+		Body(data).
+		Org(org)
 
 	// Don't set the encoding header for empty bodies, like those used for validation.
 	if len(data) > 0 {
diff --git a/replications/service_test.go b/replications/service_test.go
index 9bd73e91e7d..52b991dcade 100644
--- a/replications/service_test.go
+++ b/replications/service_test.go
@@ -89,10 +89,11 @@ var (
 		RemoteBucketID:    replication1.RemoteBucketID,
 		MaxQueueSizeBytes: replication1.MaxQueueSizeBytes,
 	}
+	remoteID   = platform.ID(888888)
 	httpConfig = influxdb.ReplicationHTTPConfig{
 		RemoteURL:        fmt.Sprintf("http://%s.cloud", replication1.RemoteID),
 		RemoteToken:      replication1.RemoteID.String(),
-		RemoteOrgID:      platform.ID(888888),
+		RemoteOrgID:      &remoteID,
 		AllowInsecureTLS: true,
 		RemoteBucketID:   replication1.RemoteBucketID,
 	}
diff --git a/sqlite/migrations/0008_migrate_remotes_null_remote_org.down.sql b/sqlite/migrations/0008_migrate_remotes_null_remote_org.down.sql
new file mode 100644
index 00000000000..c5266263c63
--- /dev/null
+++ b/sqlite/migrations/0008_migrate_remotes_null_remote_org.down.sql
@@ -0,0 +1,84 @@
+-- Adds the "NOT NULL" to remote_org_id
+ALTER TABLE remotes RENAME TO _remotes_old;
+
+CREATE TABLE remotes (
+    id VARCHAR(16) NOT NULL PRIMARY KEY,
+    org_id VARCHAR(16) NOT NULL,
+    name TEXT NOT NULL,
+    description TEXT,
+    remote_url TEXT NOT NULL,
+    remote_api_token TEXT NOT NULL,
+    remote_org_id VARCHAR(16) NOT NULL,
+    allow_insecure_tls BOOLEAN NOT NULL,
+    created_at TIMESTAMP NOT NULL,
+    updated_at TIMESTAMP NOT NULL,
+
+    CONSTRAINT remotes_uniq_orgid_name UNIQUE (org_id, name)
+);
+
+INSERT INTO remotes (
+    id,
+    org_id,
+    name,
+    description,
+    remote_url,
+    remote_api_token,
+    remote_org_id,
+    allow_insecure_tls,
+    created_at,
+    updated_at
+) SELECT * FROM _remotes_old WHERE remote_org_id IS NOT NULL;
+
+-- Edit the replications table as the remotes table key has changed
+ALTER TABLE replications RENAME TO _replications_old;
+
+CREATE TABLE replications
+(
+    id                       VARCHAR(16) NOT NULL PRIMARY KEY,
+    org_id                   VARCHAR(16) NOT NULL,
+    name                     TEXT        NOT NULL,
+    description              TEXT,
+    remote_id                VARCHAR(16) NOT NULL,
+    local_bucket_id          VARCHAR(16) NOT NULL,
+    remote_bucket_id         VARCHAR(16),
+    remote_bucket_name       TEXT DEFAULT '',
+    max_queue_size_bytes     INTEGER     NOT NULL,
+    max_age_seconds          INTEGER     NOT NULL,
+    latest_response_code     INTEGER,
+    latest_error_message     TEXT,
+    drop_non_retryable_data  BOOLEAN     NOT NULL,
+    created_at               TIMESTAMP   NOT NULL,
+    updated_at               TIMESTAMP   NOT NULL,
+
+    CONSTRAINT replications_uniq_orgid_name UNIQUE (org_id, name),
+    CONSTRAINT replications_one_of_id_name CHECK (remote_bucket_id IS NOT NULL OR remote_bucket_name != '')
+ );
+
+INSERT INTO replications (
+    id,
+    org_id,
+    name,
+    description,
+    remote_id,
+    local_bucket_id,
+    remote_bucket_id,
+    remote_bucket_name,
+    max_queue_size_bytes,
+    max_age_seconds,
+    latest_response_code,
+    latest_error_message,
+    drop_non_retryable_data,
+    created_at,
+    updated_at
+) SELECT * FROM _replications_old;
+DROP TABLE _replications_old;
+DROP TABLE _remotes_old;
+
+-- The DROP _remotes has to be at the end due to the FK from replications remote_id to remotes id.
+-- The replications table will follow the ALTER TABLE and FK to _remotes until we
+-- reinsert. By putting the DROP after all the data is re-entered, it will stay consistent throughout the process.
+
+-- Create indexes on lookup patterns we expect to be common
+CREATE INDEX idx_local_bucket_id_per_org ON replications (org_id, local_bucket_id);
+-- Create indexes on lookup patterns we expect to be common
+CREATE INDEX idx_remote_url_per_org ON remotes (org_id, remote_url);
diff --git a/sqlite/migrations/0008_migrate_remotes_null_remote_org.up.sql b/sqlite/migrations/0008_migrate_remotes_null_remote_org.up.sql
new file mode 100644
index 00000000000..539e0855182
--- /dev/null
+++ b/sqlite/migrations/0008_migrate_remotes_null_remote_org.up.sql
@@ -0,0 +1,81 @@
+-- Removes the "NOT NULL" from remote_org_id
+ALTER TABLE remotes RENAME TO _remotes_old;
+
+CREATE TABLE remotes (
+    id VARCHAR(16) NOT NULL PRIMARY KEY,
+    org_id VARCHAR(16) NOT NULL,
+    name TEXT NOT NULL,
+    description TEXT,
+    remote_url TEXT NOT NULL,
+    remote_api_token TEXT NOT NULL,
+    remote_org_id VARCHAR(16),
+    allow_insecure_tls BOOLEAN NOT NULL,
+    created_at TIMESTAMP NOT NULL,
+    updated_at TIMESTAMP NOT NULL,
+
+    CONSTRAINT remotes_uniq_orgid_name UNIQUE (org_id, name)
+);
+
+INSERT INTO remotes (
+    id,
+    org_id,
+    name,
+    description,
+    remote_url,
+    remote_api_token,
+    remote_org_id,
+    allow_insecure_tls,
+    created_at,
+    updated_at
+) SELECT * FROM _remotes_old;
+DROP TABLE _remotes_old;
+-- Create indexes on lookup patterns we expect to be common
+CREATE INDEX idx_remote_url_per_org ON remotes (org_id, remote_url);
+
+-- Edit the replications table as the remotes table key has changed
+ALTER TABLE replications RENAME TO _replications_old;
+
+CREATE TABLE replications
+(
+    id                       VARCHAR(16) NOT NULL PRIMARY KEY,
+    org_id                   VARCHAR(16) NOT NULL,
+    name                     TEXT        NOT NULL,
+    description              TEXT,
+    remote_id                VARCHAR(16) NOT NULL,
+    local_bucket_id          VARCHAR(16) NOT NULL,
+    remote_bucket_id         VARCHAR(16),
+    remote_bucket_name       TEXT DEFAULT '',
+    max_queue_size_bytes     INTEGER     NOT NULL,
+    max_age_seconds          INTEGER     NOT NULL,
+    latest_response_code     INTEGER,
+    latest_error_message     TEXT,
+    drop_non_retryable_data  BOOLEAN     NOT NULL,
+    created_at               TIMESTAMP   NOT NULL,
+    updated_at               TIMESTAMP   NOT NULL,
+
+    CONSTRAINT replications_uniq_orgid_name UNIQUE (org_id, name),
+    CONSTRAINT replications_one_of_id_name CHECK (remote_bucket_id IS NOT NULL OR remote_bucket_name != ''),
+    FOREIGN KEY (remote_id) REFERENCES remotes (id)
+ );
+
+INSERT INTO replications (
+    id,
+    org_id,
+    name,
+    description,
+    remote_id,
+    local_bucket_id,
+    remote_bucket_id,
+    remote_bucket_name,
+    max_queue_size_bytes,
+    max_age_seconds,
+    latest_response_code,
+    latest_error_message,
+    drop_non_retryable_data,
+    created_at,
+    updated_at
+) SELECT * FROM _replications_old;
+DROP TABLE _replications_old;
+
+-- Create indexes on lookup patterns we expect to be common
+CREATE INDEX idx_local_bucket_id_per_org ON replications (org_id, local_bucket_id);