count=$(echo "${OUTPUT}" | grep -Eci 'UPDATE dhcp6_subnet SET shared_network_name = NULL') || true
assert_eq 1 "${count}" "function func_dhcp6_shared_network_BDEL() is missing changed line. (expected count %d, returned %d)"
+
+ # user_context should have been added to dhcp4_client_class
+ qry="select user_context from dhcp4_client_class limit 1;"
+ run_command \
+ pgsql_execute "${qry}"
+ assert_eq 0 "${EXIT_CODE}" "${qry}. (expected status code %d, returned %d)"
+
+ # user_context should have been added to dhcp6_client_class
+ qry="select user_context from dhcp6_client_class limit 1;"
+ run_command \
+ pgsql_execute "${qry}"
+ assert_eq 0 "${EXIT_CODE}" "${qry}. (expected status code %d, returned %d)"
}
pgsql_upgrade_test() {
// modification_ts
last_client_class->setModificationTime(worker.getTimestamp(12));
+ // user_context at 13.
+ if (!worker.isColumnNull(13)) {
+ ElementPtr user_context = worker.getJSON(13);
+ if (user_context) {
+ last_client_class->setContext(user_context);
+ }
+ }
+
class_list.push_back(last_client_class);
}
- // Check for new server tags at 35.
- if (!worker.isColumnNull(35)) {
- std::string new_tag = worker.getString(35);
+ // Check for new server tags at 36.
+ if (!worker.isColumnNull(36)) {
+ std::string new_tag = worker.getString(36);
if (last_tag != new_tag) {
if (!new_tag.empty() && !last_client_class->hasServerTag(ServerTag(new_tag))) {
last_client_class->setServerTag(new_tag);
}
}
- // Parse client class specific option definition from 13 to 22.
- if (!worker.isColumnNull(13) &&
- (last_option_def_id < worker.getBigInt(13))) {
- last_option_def_id = worker.getBigInt(13);
+ // Parse client class specific option definition from 14 to 23.
+ if (!worker.isColumnNull(14) &&
+ (last_option_def_id < worker.getBigInt(14))) {
+ last_option_def_id = worker.getBigInt(14);
- auto def = processOptionDefRow(worker, 13);
+ auto def = processOptionDefRow(worker, 14);
if (def) {
last_client_class->getCfgOptionDef()->add(def);
}
}
- // Parse client class specific option from 23 to 34.
- if (!worker.isColumnNull(23) &&
- (last_option_id < worker.getBigInt(23))) {
- last_option_id = worker.getBigInt(23);
+ // Parse client class specific option from 24 to 35.
+ if (!worker.isColumnNull(24) &&
+ (last_option_id < worker.getBigInt(24))) {
+ last_option_id = worker.getBigInt(24);
- OptionDescriptorPtr desc = processOptionRow(Option::V4, worker, 23);
+ OptionDescriptorPtr desc = processOptionRow(Option::V4, worker, 24);
if (desc) {
last_client_class->getCfgOption()->add(*desc, desc->space_name_);
}
}
in_bindings.addTimestamp(client_class->getModificationTime());
+ in_bindings.add(client_class->getContext());
PgSqlTransaction transaction(conn_);
// Insert client class.
{
// PgSqlConfigBackendDHCPv4Impl::INSERT_CLIENT_CLASS4,
- 12,
+ 13,
{
OID_VARCHAR, // 1 name
OID_TEXT, // 2 test
OID_INT8, // 9 max_valid_lifetime
OID_BOOL, // 10 depend_on_known_directly
OID_VARCHAR, // 11 follow_class_name
- OID_TIMESTAMP // 12 modification_ts
+ OID_TIMESTAMP, // 12 modification_ts
+ OID_TEXT // 13 user_context cast as JSON
},
"INSERT_CLIENT_CLASS4",
"INSERT INTO dhcp4_client_class("
" max_valid_lifetime,"
" depend_on_known_directly,"
" follow_class_name,"
- " modification_ts"
+ " modification_ts, "
+ " user_context "
") VALUES ("
- "$1, $2, cast($3 as inet), $4, $5, $6, $7, $8, $9, $10, $11, $12"
+ "$1, $2, cast($3 as inet), $4, $5, $6, $7, $8, $9, $10, $11, $12, cast($13 as JSON)"
")"
},
// Update existing client class with specifying its position.
{
// PgSqlConfigBackendDHCPv4Impl::UPDATE_CLIENT_CLASS4,
- 13,
+ 14,
{
OID_VARCHAR, // 1 name
OID_TEXT, // 2 test
OID_BOOL, // 10 depend_on_known_directly
OID_VARCHAR, // 11 follow_class_name
OID_TIMESTAMP, // 12 modification_ts
- OID_VARCHAR // 13 name (of class to update)
+ OID_TEXT, // 13 user_context cast as JSON
+ OID_VARCHAR // 14 name (of class to update)
},
"UPDATE_CLIENT_CLASS4",
PGSQL_UPDATE_CLIENT_CLASS4("follow_class_name = $11,")
// Update existing client class without specifying its position.
{
// PgSqlConfigBackendDHCPv4Impl::UPDATE_CLIENT_CLASS4_SAME_POSITION,
- 13,
+ 14,
{
OID_VARCHAR, // 1 name
OID_TEXT, // 2 test
OID_BOOL, // 10 depend_on_known_directly
OID_VARCHAR, // 11 follow_class_name
OID_TIMESTAMP, // 12 modification_ts
- OID_VARCHAR // 13 name (of class to update)
+ OID_TEXT, // 13 user_context cast as JSON
+ OID_VARCHAR // 14 name (of class to update)
},
"UPDATE_CLIENT_CLASS4_SAME_POSITION",
PGSQL_UPDATE_CLIENT_CLASS4("")
// modification_ts
last_client_class->setModificationTime(worker.getTimestamp(9));
- // class specific option definition from 10 to 19.
- // class specific option from 20 to 31.
+ // user_context at 10.
+ if (!worker.isColumnNull(10)) {
+ ElementPtr user_context = worker.getJSON(10);
+ if (user_context) {
+ last_client_class->setContext(user_context);
+ }
+ }
+
+ // class specific option definition from 11 to 20.
+ // class specific option from 21 to 32.
// preferred lifetime: default, min, max
- last_client_class->setPreferred(worker.getTriplet(33, 34, 35));
+ last_client_class->setPreferred(worker.getTriplet(34, 35, 36));
class_list.push_back(last_client_class);
}
- // Check for new server tags at 32.
- if (!worker.isColumnNull(32)) {
- std::string new_tag = worker.getString(32);
+ // Check for new server tags at 33.
+ if (!worker.isColumnNull(33)) {
+ std::string new_tag = worker.getString(33);
if (last_tag != new_tag) {
if (!new_tag.empty() && !last_client_class->hasServerTag(ServerTag(new_tag))) {
last_client_class->setServerTag(new_tag);
}
}
- // Parse client class specific option definition from 10 to 19.
- if (!worker.isColumnNull(10) &&
- (last_option_def_id < worker.getBigInt(10))) {
- last_option_def_id = worker.getBigInt(10);
+ // Parse client class specific option definition from 11 to 20.
+ if (!worker.isColumnNull(11) &&
+ (last_option_def_id < worker.getBigInt(11))) {
+ last_option_def_id = worker.getBigInt(11);
- auto def = processOptionDefRow(worker, 10);
+ auto def = processOptionDefRow(worker, 11);
if (def) {
last_client_class->getCfgOptionDef()->add(def);
}
}
- // Parse client class specific option from 20 to 31.
- if (!worker.isColumnNull(20) &&
- (last_option_id < worker.getBigInt(20))) {
- last_option_id = worker.getBigInt(20);
+ // Parse client class specific option from 21 to 32.
+ if (!worker.isColumnNull(21) &&
+ (last_option_id < worker.getBigInt(21))) {
+ last_option_id = worker.getBigInt(21);
- OptionDescriptorPtr desc = processOptionRow(Option::V6, worker, 20);
+ OptionDescriptorPtr desc = processOptionRow(Option::V6, worker, 21);
if (desc) {
last_client_class->getCfgOption()->add(*desc, desc->space_name_);
}
in_bindings.add(client_class->getPreferred().getMin());
in_bindings.add(client_class->getPreferred().getMax());
in_bindings.addTimestamp(client_class->getModificationTime());
+ in_bindings.add(client_class->getContext());
PgSqlTransaction transaction(conn_);
// Insert client class.
{
// PgSqlConfigBackendDHCPv6Impl::INSERT_CLIENT_CLASS6,
- 12,
+ 13,
{
OID_VARCHAR, // 1 name
OID_TEXT, // 2 test
OID_INT8, // 9 preferred_lifetime
OID_INT8, // 10 min_preferred_lifetime
OID_INT8, // 11 max_preferred_lifetime
- OID_TIMESTAMP // 12 modification_ts
+ OID_TIMESTAMP, // 12 modification_ts
+ OID_TEXT // 13 user_context cast as JSON
},
"INSERT_CLIENT_CLASS6",
"INSERT INTO dhcp6_client_class("
" preferred_lifetime,"
" min_preferred_lifetime,"
" max_preferred_lifetime,"
- " modification_ts"
+ " modification_ts,"
+ " user_context "
") VALUES ("
- " $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12"
+ " $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, cast($13 as JSON)"
")"
},
// Update existing client class with specifying its position.
{
// PgSqlConfigBackendDHCPv6Impl::UPDATE_CLIENT_CLASS6,
- 13,
+ 14,
{
OID_VARCHAR, // 1 name
OID_TEXT, // 2 test
OID_INT8, // 10 min_preferred_lifetime
OID_INT8, // 11 max_preferred_lifetime
OID_TIMESTAMP, // 12 modification_ts
- OID_VARCHAR // 13 name (of class to update)
+ OID_TEXT, // 13 user_conetx
+ OID_VARCHAR // 14 name (of class to update)
},
"UPDATE_CLIENT_CLASS6",
PGSQL_UPDATE_CLIENT_CLASS6("follow_class_name = $8,")
// Update existing client class without specifying its position.
{
// PgSqlConfigBackendDHCPv6Impl::UPDATE_CLIENT_CLASS6_SAME_POSITION,
- 13,
+ 14,
{
OID_VARCHAR, // 1 name
OID_TEXT, // 2 test
OID_INT8, // 10 min_preferred_lifetime
OID_INT8, // 11 max_preferred_lifetime
OID_TIMESTAMP, // 12 modification_ts
- OID_VARCHAR // 13 name (of class to update)
+ OID_TEXT, // 13 user_conetx
+ OID_VARCHAR // 14 name (of class to update)
},
"UPDATE_CLIENT_CLASS6_SAME_POSITION",
PGSQL_UPDATE_CLIENT_CLASS6("")
" c.depend_on_known_directly," \
" o.depend_on_known_indirectly, " \
" gmt_epoch(c.modification_ts) as modification_ts, " \
+ " c.user_context," \
" d.id," \
" d.code," \
" d.name," \
" c.depend_on_known_directly," \
" o.depend_on_known_indirectly, " \
" gmt_epoch(c.modification_ts) as modification_ts, " \
+ " c.user_context, " \
" d.id," \
" d.code," \
" d.name," \
" max_valid_lifetime = $9," \
" depend_on_known_directly = $10," \
follow_class_name_set \
- " modification_ts = $12 " \
- "WHERE name = $13"
+ " modification_ts = $12, " \
+ " user_context = cast($13 as json)" \
+ "WHERE name = $14"
#endif
#ifndef PGSQL_UPDATE_CLIENT_CLASS6
" preferred_lifetime = $9, " \
" min_preferred_lifetime = $10, " \
" max_preferred_lifetime = $11, " \
- " modification_ts = $12 " \
- "WHERE name = $13"
+ " modification_ts = $12, " \
+ " user_context = cast($13 as json) " \
+ "WHERE name = $14"
#endif
#ifndef PGSQL_UPDATE_SERVER
$dhcp6_shared_network_BDEL$
LANGUAGE plpgsql;
+-- Add user_context column to Client class tables.
+ALTER TABLE dhcp4_client_class ADD COLUMN user_context JSON DEFAULT NULL;
+ALTER TABLE dhcp6_client_class ADD COLUMN user_context JSON DEFAULT NULL;
+
-- Update the schema version number.
UPDATE schema_version
SET version = '12', minor = '0';
\$dhcp6_shared_network_BDEL\$
LANGUAGE plpgsql;
+-- Add user_context column to Client class tables.
+ALTER TABLE dhcp4_client_class ADD COLUMN user_context JSON DEFAULT NULL;
+ALTER TABLE dhcp6_client_class ADD COLUMN user_context JSON DEFAULT NULL;
+
-- Update the schema version number.
UPDATE schema_version
SET version = '12', minor = '0';