Skip to content

Instantly share code, notes, and snippets.

@mgagne
Created June 10, 2016 23:14
Show Gist options
  • Save mgagne/0df3bb707176f2401fdd0b99915c5fdd to your computer and use it in GitHub Desktop.
Save mgagne/0df3bb707176f2401fdd0b99915c5fdd to your computer and use it in GitHub Desktop.
Create admin account in Gerrit
-- Insert the base values for the initial Gerrit user. This user will
-- become the administrator of the server. As this user is a local
-- user it will not be able to login through the web UI.
START TRANSACTION;
SET @gerrit_admin_account_id = {{ gerrit_admin_account_id }};
SET @gerrit_admin_group_id = 1;
-- Create a local user, we need to insert for this.
INSERT INTO account_external_ids
SET account_id = @gerrit_admin_account_id,
email_address = NULL,
password = NULL,
external_id = 'username:{{ gerrit_admin_account_name }}';
INSERT INTO account_external_ids
SET account_id = @gerrit_admin_account_id,
email_address = '{{ gerrit_admin_account_email }}',
password = NULL,
external_id = 'mailto:{{ gerrit_admin_account_email }}';
-- Add local user to administrator group.
INSERT INTO account_group_members
SET account_id = @gerrit_admin_account_id,
group_id = @gerrit_admin_group_id;
-- Insert the audit information.
INSERT INTO account_group_members_audit
SET added_by = @gerrit_admin_account_id,
removed_by = NULL,
removed_on = NULL,
account_id = @gerrit_admin_account_id,
group_id = @gerrit_admin_group_id,
added_on = NOW();
-- Set the sequence next value to increment to 1000001.
SET @sql = CONCAT('ALTER TABLE account_id AUTO_INCREMENT = ', @gerrit_admin_account_id + 1);
PREPARE stmt FROM @sql;
EXECUTE stmt;
-- Insert the public SSH key for the administrator account.
INSERT INTO account_ssh_keys
SET ssh_public_key = '{{ gerrit_admin_account_ssh_public_key }}',
valid = 'Y',
account_id = @gerrit_admin_account_id,
seq = 1;
-- Insert the internal Gerrit user which is connected to the
-- account_external_id we created before.
INSERT INTO accounts
SET registered_on = NULL,
full_name = '{{ gerrit_admin_account_fullname }}',
preferred_email = NULL,
contact_filed_on = NULL,
maximum_page_size = 25,
show_site_header = 'Y',
use_flash_clipboard = 'Y',
download_url = NULL,
download_command = NULL,
copy_self_on_email = 'N',
date_format = NULL,
time_format = NULL,
relative_date_in_change_table = 'N',
diff_view = NULL,
size_bar_in_change_table = 'Y',
legacycid_in_change_table = 'N',
review_category_strategy = NULL,
mute_common_path_prefixes = 'Y',
inactive = 'N',
account_id = @gerrit_admin_account_id;
COMMIT;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment