Defined Type: cassandra::schema::table
- Defined in:
- manifests/schema/table.pp
Overview
Create or drop tables within the schema.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'manifests/schema/table.pp', line 19
define cassandra::schema::table (
$keyspace,
$ensure = present,
$columns = {},
$options = [],
$table = $title,
){
include 'cassandra::schema'
$read_script = "DESC TABLE ${keyspace}.${table}"
$read_command = "${::cassandra::schema::cqlsh_opts} -e \"${read_script}\" ${::cassandra::schema::cqlsh_conn}"
if $ensure == present {
$create_script1 = "CREATE TABLE IF NOT EXISTS ${keyspace}.${table}"
$cols_def = join(join_keys_to_values($columns, ' '), ', ')
$cols_def_rm_collection_type = delete($cols_def, 'COLLECTION-TYPE ')
if count($options) > 0 {
$options_def = join($options, ' AND ')
$create_script = "${create_script1} (${cols_def_rm_collection_type}) WITH ${options_def}"
} else {
$create_script = "${create_script1} (${cols_def_rm_collection_type})"
}
$create_command = "${::cassandra::schema::cqlsh_opts} -e \"${create_script}\" ${::cassandra::schema::cqlsh_conn}"
exec { $create_command:
unless => $read_command,
require => Exec['::cassandra::schema connection test'],
}
} elsif $ensure == absent {
$delete_script = "DROP TABLE IF EXISTS ${keyspace}.${table}"
$delete_command = "${::cassandra::schema::cqlsh_opts} -e \"${delete_script}\" ${::cassandra::schema::cqlsh_conn}"
exec { $delete_command:
onlyif => $read_command,
require => Exec['::cassandra::schema connection test'],
}
} else {
fail("Unknown action (${ensure}) for ensure attribute.")
}
}
|