Skip to content

Commit

Permalink
Merge pull request #708 from timopollmeier/unique-user-name
Browse files Browse the repository at this point in the history
Add UNIQUE constraint to users name column
  • Loading branch information
mattmundell authored Aug 21, 2019
2 parents 79b8264 + 3fd5786 commit 8d5f085
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Check and create default permissions individually [#671](https://github.com/greenbone/gvmd/pull/671)
- Add -f arg to sendmail call in email alert [#676](https://github.com/greenbone/gvmd/pull/676) [#678](https://github.com/greenbone/gvmd/pull/678)
- Change get_tickets to use the status text for filtering. [#697](https://github.com/greenbone/gvmd/pull/697)
- Made checks to prevent duplicate user names stricter. [#708](https://github.com/greenbone/gvmd/pull/708)

### Fixed
- A PostgreSQL statement order issue [#611](https://github.com/greenbone/gvmd/issues/611) has been addressed [#642](https://github.com/greenbone/gvmd/pull/642)
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ include (CPack)

## Variables

set (GVMD_DATABASE_VERSION 217)
set (GVMD_DATABASE_VERSION 218)

set (GVMD_SCAP_DATABASE_VERSION 15)

Expand Down
34 changes: 34 additions & 0 deletions src/manage_migrators.c
Original file line number Diff line number Diff line change
Expand Up @@ -1284,6 +1284,39 @@ migrate_216_to_217 ()
return 0;
}

/**
* @brief Migrate the database from version 217 to version 218.
*
* @return 0 success, -1 error.
*/
int
migrate_217_to_218 ()
{
sql_begin_immediate ();

/* Ensure that the database is currently version 217. */

if (manage_db_version () != 217)
{
sql_rollback ();
return -1;
}

/* Update the database. */

/* Add an UNIQUE constraint to the name column of users */

sql ("ALTER TABLE users ADD UNIQUE (name);");

/* Set the database version to 218. */

set_db_version (218);

sql_commit ();

return 0;
}

#undef UPDATE_DASHBOARD_SETTINGS

/**
Expand All @@ -1307,6 +1340,7 @@ static migrator_t database_migrators[] = {
{215, migrate_214_to_215},
{216, migrate_215_to_216},
{217, migrate_216_to_217},
{218, migrate_217_to_218},
/* End marker. */
{-1, NULL}};

Expand Down
2 changes: 1 addition & 1 deletion src/manage_pg.c
Original file line number Diff line number Diff line change
Expand Up @@ -2058,7 +2058,7 @@ create_tables ()
" (id SERIAL PRIMARY KEY,"
" uuid text UNIQUE NOT NULL,"
" owner integer REFERENCES users (id) ON DELETE RESTRICT,"
" name text NOT NULL,"
" name text UNIQUE NOT NULL,"
" comment text,"
" password text,"
" timezone text,"
Expand Down

0 comments on commit 8d5f085

Please sign in to comment.