Skip to content

Commit 4e06277

Browse files
committed
Creating a database multiple times is a no-op
Creating a database multiple times does no longer throw an error and passing 'IF NOT EXISTS' to CREATE DATABASE does nothing at the moment and will be deprecated in 1.0.
1 parent 68c95e5 commit 4e06277

File tree

3 files changed

+2
-30
lines changed

3 files changed

+2
-30
lines changed

influxdb/client.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -465,16 +465,13 @@ def get_list_database(self):
465465
"""
466466
return list(self.query("SHOW DATABASES").get_points())
467467

468-
def create_database(self, dbname, if_not_exists=False):
468+
def create_database(self, dbname):
469469
"""Create a new database in InfluxDB.
470470
471471
:param dbname: the name of the database to create
472472
:type dbname: str
473473
"""
474-
if if_not_exists:
475-
self.query("CREATE DATABASE IF NOT EXISTS \"%s\"" % dbname)
476-
else:
477-
self.query("CREATE DATABASE \"%s\"" % dbname)
474+
self.query("CREATE DATABASE \"%s\"" % dbname)
478475

479476
def drop_database(self, dbname):
480477
"""Drop a database from InfluxDB.

influxdb/tests/client_test.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -418,19 +418,6 @@ def test_create_database(self):
418418
'create database "new_db"'
419419
)
420420

421-
def test_create_database_with_exist_check(self):
422-
with requests_mock.Mocker() as m:
423-
m.register_uri(
424-
requests_mock.GET,
425-
"http://localhost:8086/query",
426-
text='{"results":[{}]}'
427-
)
428-
self.cli.create_database('new_db', if_not_exists=True)
429-
self.assertEqual(
430-
m.last_request.qs['q'][0],
431-
'create database if not exists "new_db"'
432-
)
433-
434421
def test_create_numeric_named_database(self):
435422
with requests_mock.Mocker() as m:
436423
m.register_uri(

influxdb/tests/server_tests/client_test_with_server.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -133,18 +133,6 @@ def test_create_database(self):
133133
[{'name': 'new_db_1'}, {'name': 'new_db_2'}]
134134
)
135135

136-
def test_create_database_twice_if_not_exist(self):
137-
self.assertIsNone(self.cli.create_database('new_db'))
138-
self.assertIsNone(
139-
self.cli.create_database('new_db', if_not_exists=True))
140-
141-
def test_create_database_twice_fails(self):
142-
self.assertIsNone(self.cli.create_database('new_db'))
143-
with self.assertRaises(InfluxDBClientError) as ctx:
144-
self.cli.create_database('new_db')
145-
self.assertEqual('database already exists',
146-
ctx.exception.content)
147-
148136
def test_get_list_series_empty(self):
149137
rsp = self.cli.get_list_series()
150138
self.assertEqual([], rsp)

0 commit comments

Comments
 (0)