|
146 | 146 |
|
147 | 147 | context 'ttl' do |
148 | 148 | let(:directory) { 'dsl_table_with_ttl' } |
| 149 | + |
149 | 150 | it 'creates a table with table-level and column-level TTL' do |
150 | 151 | subject |
151 | 152 |
|
|
162 | 163 | create_sql = ActiveRecord::Base.connection.show_create_table('some') |
163 | 164 | expect(create_sql).to include('TTL date + toIntervalDay(30)') |
164 | 165 | end |
| 166 | + |
| 167 | + it 'creates a table with TTL using correct statement order' do |
| 168 | + subject |
| 169 | + |
| 170 | + current_schema = schema(model) |
| 171 | + |
| 172 | + # Verify TTL comes after ENGINE |
| 173 | + create_sql = ActiveRecord::Base.connection.show_create_table('some') |
| 174 | + engine_idx = create_sql.index('ENGINE = MergeTree') |
| 175 | + ttl_idx = create_sql.index('TTL date + toIntervalDay(30)') |
| 176 | + expect(engine_idx).to be < ttl_idx |
| 177 | + end |
| 178 | + end |
| 179 | + |
| 180 | + context 'settings' do |
| 181 | + let(:directory) { 'dsl_table_with_settings' } |
| 182 | + |
| 183 | + it 'creates a table with table-level SETTINGS' do |
| 184 | + subject |
| 185 | + |
| 186 | + current_schema = schema(model) |
| 187 | + |
| 188 | + expect(current_schema.keys.count).to eq(3) |
| 189 | + expect(current_schema).to have_key('an_id') |
| 190 | + expect(current_schema).to have_key('date') |
| 191 | + expect(current_schema).to have_key('data') |
| 192 | + |
| 193 | + # Verify table-level SETTINGS in SHOW CREATE TABLE |
| 194 | + create_sql = ActiveRecord::Base.connection.show_create_table('some') |
| 195 | + expect(create_sql).to include('SETTINGS allow_nullable_key = 1, index_granularity = 8192') |
| 196 | + end |
| 197 | + |
| 198 | + it 'creates a table with SETTINGS using correct statement order' do |
| 199 | + subject |
| 200 | + |
| 201 | + current_schema = schema(model) |
| 202 | + |
| 203 | + # Verify TTL comes before SETTINGS |
| 204 | + create_sql = ActiveRecord::Base.connection.show_create_table('some') |
| 205 | + ttl_idx = create_sql.index('TTL date') |
| 206 | + settings_idx = create_sql.index('SETTINGS') |
| 207 | + expect(ttl_idx).to be < settings_idx |
| 208 | + end |
| 209 | + |
| 210 | + it 'dumps SETTINGS as separate option' do |
| 211 | + require 'clickhouse-activerecord/schema_dumper' |
| 212 | + |
| 213 | + subject |
| 214 | + |
| 215 | + schema = StringIO.new |
| 216 | + ClickhouseActiverecord::SchemaDumper.dump(ActiveRecord::Base.connection, schema) |
| 217 | + schema_string = schema.string |
| 218 | + |
| 219 | + expect(schema_string).to include('options: "MergeTree ORDER BY an_id"') |
| 220 | + expect(schema_string).to include('ttl: "date + toIntervalDay(30)"') |
| 221 | + expect(schema_string).to include('settings: "allow_nullable_key = 1, index_granularity = 8192"') |
| 222 | + end |
165 | 223 | end |
166 | 224 |
|
167 | 225 | context 'datetime' do |
|
0 commit comments