|
1 | | -# Copyright 2024 Google LLC All rights reserved. |
| 1 | +# Copyright 2025 Google LLC All rights reserved. |
2 | 2 | # |
3 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
4 | 4 | # you may not use this file except in compliance with the License. |
@@ -62,6 +62,65 @@ def test_create_table(self): |
62 | 62 | requests[0].statements[0], |
63 | 63 | ) |
64 | 64 |
|
| 65 | + def test_create_auto_increment_table(self): |
| 66 | + from test.mockserver_tests.auto_increment_model import Base |
| 67 | + |
| 68 | + add_result( |
| 69 | + """SELECT true |
| 70 | +FROM INFORMATION_SCHEMA.TABLES |
| 71 | +WHERE TABLE_SCHEMA="" AND TABLE_NAME="singers" |
| 72 | +LIMIT 1 |
| 73 | +""", |
| 74 | + ResultSet(), |
| 75 | + ) |
| 76 | + engine = create_engine( |
| 77 | + "spanner:///projects/p/instances/i/databases/d", |
| 78 | + connect_args={"client": self.client, "pool": FixedSizePool(size=10)}, |
| 79 | + ) |
| 80 | + engine.dialect.use_auto_increment = True |
| 81 | + Base.metadata.create_all(engine) |
| 82 | + requests = self.database_admin_service.requests |
| 83 | + eq_(1, len(requests)) |
| 84 | + is_instance_of(requests[0], UpdateDatabaseDdlRequest) |
| 85 | + eq_(1, len(requests[0].statements)) |
| 86 | + eq_( |
| 87 | + "CREATE TABLE singers (\n" |
| 88 | + "\tid INT64 NOT NULL AUTO_INCREMENT, \n" |
| 89 | + "\tname STRING(MAX) NOT NULL\n" |
| 90 | + ") PRIMARY KEY (id)", |
| 91 | + requests[0].statements[0], |
| 92 | + ) |
| 93 | + |
| 94 | + def test_create_table_with_specific_sequence_kind(self): |
| 95 | + from test.mockserver_tests.auto_increment_model import Base |
| 96 | + |
| 97 | + add_result( |
| 98 | + """SELECT true |
| 99 | +FROM INFORMATION_SCHEMA.TABLES |
| 100 | +WHERE TABLE_SCHEMA="" AND TABLE_NAME="singers" |
| 101 | +LIMIT 1 |
| 102 | +""", |
| 103 | + ResultSet(), |
| 104 | + ) |
| 105 | + engine = create_engine( |
| 106 | + "spanner:///projects/p/instances/i/databases/d", |
| 107 | + connect_args={"client": self.client, "pool": FixedSizePool(size=10)}, |
| 108 | + ) |
| 109 | + engine.dialect.default_sequence_kind = "non_existing_kind" |
| 110 | + Base.metadata.create_all(engine) |
| 111 | + requests = self.database_admin_service.requests |
| 112 | + eq_(1, len(requests)) |
| 113 | + is_instance_of(requests[0], UpdateDatabaseDdlRequest) |
| 114 | + eq_(1, len(requests[0].statements)) |
| 115 | + eq_( |
| 116 | + "CREATE TABLE singers (\n" |
| 117 | + "\tid INT64 NOT NULL " |
| 118 | + "GENERATED BY DEFAULT AS IDENTITY (non_existing_kind), \n" |
| 119 | + "\tname STRING(MAX) NOT NULL\n" |
| 120 | + ") PRIMARY KEY (id)", |
| 121 | + requests[0].statements[0], |
| 122 | + ) |
| 123 | + |
65 | 124 | def test_insert_row(self): |
66 | 125 | from test.mockserver_tests.auto_increment_model import Singer |
67 | 126 |
|
|
0 commit comments