Skip to content

Commit

Permalink
Merge branch 'main' into priyanshi/refactor-analyze
Browse files Browse the repository at this point in the history
  • Loading branch information
priyanshi-yb committed Dec 4, 2024
2 parents 9b170e6 + 995f770 commit 936b885
Show file tree
Hide file tree
Showing 17 changed files with 1,489 additions and 57 deletions.
37 changes: 37 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
### Describe the changes in this pull request


### Describe if there are any user-facing changes
<!--
Clarify any changes to the user experience. For instance,
1. Were there any changes to the command line?
2. Were there any changes to the configuration?
3. Has the installation process changed?
4. Were there any changes to the reports?
-->

### How was this pull request tested?
<!--
Mention if the existing tests were enough
Mention the new unit tests added
Was any manual testing needed? If yes, is there a need to add integration tests for that?
-->

### Does your PR have changes that can cause upgrade issues?
| Component | Breaking changes? |
| :----------------------------------------------: | :-----------: |
| MetaDB | Yes/No |
| Name registry json | Yes/No |
| Data File Descriptor Json | Yes/No |
| Export Snapshot Status Json | Yes/No |
| Import Data State | Yes/No |
| Export Status Json | Yes/No |
| Data .sql files of tables | Yes/No |
| Export and import data queue | Yes/No |
| Schema Dump | Yes/No |
| AssessmentDB | Yes/No |
| Sizing DB | Yes/No |
| Migration Assessment Report Json | Yes/No |
| Callhome Json | Yes/No |
| YugabyteD Tables | Yes/No |
| TargetDB Metadata Tables | Yes/No |
55 changes: 37 additions & 18 deletions installer_scripts/install-voyager-airgapped.sh
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,12 @@ install_perl_module() {
local requirement_type="$2"
local required_version="$3"
local package="$4"

echo "Installing module $module_name..."

# Check if the module is already installed and meets the version requirements
check_perl_module_version "$module_name" "$requirement_type" "$required_version" "true"
if [[ $? -eq 0 ]]; then
return
fi

# Extract the package
tar -xzvf "$package" 1>&2 || { echo "Error: Failed to extract $package"; exit 1; }
Expand Down Expand Up @@ -183,35 +187,56 @@ install_perl_module() {
# Return to the original directory
cd ..

# Verification and version check
# Verification of the installed module
check_perl_module_version "$module_name" "$requirement_type" "$required_version" "false"
if [[ $? -ne 0 ]]; then
exit 1
fi
}

check_perl_module_version() {
local module_name="$1"
local requirement_type="$2"
local required_version="$3"
local check_only="$4" # If "true", suppress error messages and exit silently

# Get installed version
local installed_version
installed_version=$(perl -M"$module_name" -e 'print $'"$module_name"'::VERSION' 2> /dev/null)

if [[ -z "$installed_version" ]]; then
echo "Error: $module_name could not be loaded or found."
exit 1
if [[ "$check_only" != "true" ]]; then
echo "Error: $module_name could not be loaded or found."
fi
return 1
fi

# Version comparison based on requirement type
if [[ "$requirement_type" == "min" ]]; then
# Check if installed version is at least the required version
if [[ $(echo -e "$installed_version\n$required_version" | sort -V | head -n1) != "$required_version" ]]; then
if [[ $(echo -e "$installed_version\n$required_version" | sort -V | head -n1) == "$required_version" ]]; then
return 0
fi
if [[ "$check_only" != "true" ]]; then
echo "Error: Installed version of $module_name ($installed_version) does not meet the minimum required version ($required_version)."
exit 1
fi
return 1
elif [[ "$requirement_type" == "exact" ]]; then
# Check if installed version matches the required version exactly
if [[ "$installed_version" != "$required_version" ]]; then
if [[ "$installed_version" == "$required_version" ]]; then
return 0
fi
if [[ "$check_only" != "true" ]]; then
echo "Error: Installed version of $module_name ($installed_version) does not match the exact required version ($required_version)."
exit 1
fi
return 1
else
echo "Error: Unknown requirement type '$requirement_type' for $module_name."
exit 1
fi

echo ""
}


check_binutils_version() {
min_required_version='2.25'

Expand Down Expand Up @@ -428,9 +453,6 @@ centos_main() {
echo ""
echo -e "\e[33mYum packages:\e[0m"
print_dependencies "${centos_yum_package_requirements[@]}"
echo ""
echo -e "\e[33mCPAN modules:\e[0m"
print_dependencies "${cpan_modules_requirements[@]}"
print_steps_to_install_oic_on_centos
exit 0
fi
Expand Down Expand Up @@ -609,9 +631,6 @@ ubuntu_main() {
echo ""
echo -e "\e[33mApt packages:\e[0m"
print_dependencies "${ubuntu_apt_package_requirements[@]}"
echo ""
echo -e "\e[33mCPAN modules:\e[0m"
print_dependencies "${cpan_modules_requirements[@]}"
print_steps_to_install_oic_on_ubuntu
exit 0
fi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,90 @@ BEGIN
SELECT * FROM employees e WHERE e.xmax = (SELECT MAX(xmax) FROM employees WHERE department = e.department);

END;
$$;
$$;

CREATE FUNCTION public.get_employeee_salary(emp_id integer) RETURNS numeric
LANGUAGE plpgsql
AS $$
DECLARE
emp_salary employees.salary%TYPE; -- Declare a variable with the same type as employees.salary
BEGIN
SELECT salary INTO emp_salary
FROM employees
WHERE employee_id = emp_id;
RETURN emp_salary;
END;
$$;

CREATE OR REPLACE FUNCTION calculate_tax(salary_amount NUMERIC) RETURNS NUMERIC AS $$
DECLARE
tax_rate employees.tax_rate%TYPE; -- Inherits type from employees.tax_rate column
tax_amount NUMERIC;
BEGIN
-- Assign a value to the variable
SELECT tax_rate INTO tax_rate FROM employees WHERE id = 1;

-- Use the variable in a calculation
tax_amount := salary_amount * tax_rate;
RETURN tax_amount;
END;
$$ LANGUAGE plpgsql;

CREATE OR REPLACE FUNCTION log_salary_change() RETURNS TRIGGER AS $$
DECLARE
old_salary employees.salary%TYPE; -- Matches the type of the salary column
new_salary employees.salary%TYPE;
BEGIN
old_salary := OLD.salary;
new_salary := NEW.salary;

IF new_salary <> old_salary THEN
INSERT INTO salary_log(employee_id, old_salary, new_salary, changed_at)
VALUES (NEW.id, old_salary, new_salary, now());
END IF;

RETURN NEW;
END;
$$ LANGUAGE plpgsql;

CREATE TRIGGER salary_update_trigger
AFTER UPDATE OF salary ON employees
FOR EACH ROW EXECUTE FUNCTION log_salary_change();

CREATE OR REPLACE FUNCTION get_employee_details(emp_id employees.id%Type)
RETURNS public.employees.name%Type AS $$
DECLARE
employee_name employees.name%TYPE;
BEGIN
SELECT name INTO employee_name FROM employees WHERE id = emp_id;
RETURN employee_name;
END;
$$ LANGUAGE plpgsql;


CREATE OR REPLACE FUNCTION list_high_earners(threshold NUMERIC) RETURNS VOID AS $$
DECLARE
emp_name employees.name%TYPE;
emp_salary employees.salary%TYPE;
BEGIN
FOR emp_name, emp_salary IN
SELECT name, salary FROM employees WHERE salary > threshold
LOOP
RAISE NOTICE 'Employee: %, Salary: %', emp_name, emp_salary;
END LOOP;
END;
$$ LANGUAGE plpgsql;


CREATE OR REPLACE FUNCTION copy_high_earners(threshold NUMERIC) RETURNS VOID AS $$
DECLARE
temp_salary employees.salary%TYPE;
BEGIN
CREATE TEMP TABLE temp_high_earners AS
SELECT * FROM employees WHERE salary > threshold;

FOR temp_salary IN SELECT salary FROM temp_high_earners LOOP
RAISE NOTICE 'High earner salary: %', temp_salary;
END LOOP;
END;
$$ LANGUAGE plpgsql;
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,27 @@ BEGIN
RAISE NOTICE 'Employee % of age % added successfully.', emp_name, emp_age;
END;
$$;

CREATE OR REPLACE PROCEDURE update_salary(emp_id INT, increment NUMERIC) AS $$
DECLARE
current_salary employees.salary%TYPE; -- Matches the type of the salary column
BEGIN
SELECT salary INTO current_salary FROM employees WHERE id = emp_id;

IF current_salary IS NULL THEN
RAISE NOTICE 'Employee ID % does not exist.', emp_id;
ELSE
UPDATE employees SET salary = current_salary + increment WHERE id = emp_id;
END IF;
END;
$$ LANGUAGE plpgsql;


CREATE OR REPLACE PROCEDURE get_employee_details_proc(emp_id employees.id%Type, salary employees.salary%TYPE, tax_rate numeric) AS $$
DECLARE
employee_name employees.name%TYPE;
BEGIN
SELECT name INTO employee_name FROM employees e WHERE e.id = emp_id and e.salary = salary and e.tax_rate = tax_rate;

END;
$$ LANGUAGE plpgsql;
Loading

0 comments on commit 936b885

Please sign in to comment.