mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-01-17 06:52:27 +01:00
beta preview of the upgrade script
This commit is contained in:
parent
e644e4894a
commit
4fbd88ffd7
@ -10,6 +10,7 @@
|
||||
- Updated redis to v6, with alpine image
|
||||
- Updated Sidekiq to 6.0.7
|
||||
- Updated documentation
|
||||
- Beta preview of the upgrade script
|
||||
- Fix a bug: managers do not see the name of the user who reserved a slot
|
||||
- Fix a bug: OpenAPI documentation is not available
|
||||
- Fix a bug: summary of create training availability shows incorrect alert about slot splitting
|
||||
|
@ -108,8 +108,8 @@ SET default_tablespace = '';
|
||||
|
||||
CREATE TABLE public.abuses (
|
||||
id integer NOT NULL,
|
||||
signaled_id integer,
|
||||
signaled_type character varying,
|
||||
signaled_id integer,
|
||||
first_name character varying,
|
||||
last_name character varying,
|
||||
email character varying,
|
||||
@ -187,8 +187,8 @@ CREATE TABLE public.addresses (
|
||||
locality character varying,
|
||||
country character varying,
|
||||
postal_code character varying,
|
||||
placeable_id integer,
|
||||
placeable_type character varying,
|
||||
placeable_id integer,
|
||||
created_at timestamp without time zone,
|
||||
updated_at timestamp without time zone
|
||||
);
|
||||
@ -263,8 +263,8 @@ CREATE TABLE public.ar_internal_metadata (
|
||||
|
||||
CREATE TABLE public.assets (
|
||||
id integer NOT NULL,
|
||||
viewable_id integer,
|
||||
viewable_type character varying,
|
||||
viewable_id integer,
|
||||
attachment character varying,
|
||||
type character varying,
|
||||
created_at timestamp without time zone,
|
||||
@ -504,8 +504,8 @@ ALTER SEQUENCE public.coupons_id_seq OWNED BY public.coupons.id;
|
||||
|
||||
CREATE TABLE public.credits (
|
||||
id integer NOT NULL,
|
||||
creditable_id integer,
|
||||
creditable_type character varying,
|
||||
creditable_id integer,
|
||||
plan_id integer,
|
||||
hours integer,
|
||||
created_at timestamp without time zone,
|
||||
@ -1013,8 +1013,8 @@ ALTER SEQUENCE public.invoice_items_id_seq OWNED BY public.invoice_items.id;
|
||||
|
||||
CREATE TABLE public.invoices (
|
||||
id integer NOT NULL,
|
||||
invoiced_id integer,
|
||||
invoiced_type character varying,
|
||||
invoiced_id integer,
|
||||
stp_invoice_id character varying,
|
||||
total integer,
|
||||
created_at timestamp without time zone,
|
||||
@ -1193,15 +1193,15 @@ ALTER SEQUENCE public.machines_id_seq OWNED BY public.machines.id;
|
||||
CREATE TABLE public.notifications (
|
||||
id integer NOT NULL,
|
||||
receiver_id integer,
|
||||
attached_object_id integer,
|
||||
attached_object_type character varying,
|
||||
attached_object_id integer,
|
||||
notification_type_id integer,
|
||||
is_read boolean DEFAULT false,
|
||||
created_at timestamp without time zone,
|
||||
updated_at timestamp without time zone,
|
||||
receiver_type character varying,
|
||||
is_send boolean DEFAULT false,
|
||||
meta_data jsonb DEFAULT '{}'::jsonb
|
||||
meta_data jsonb DEFAULT '"{}"'::jsonb
|
||||
);
|
||||
|
||||
|
||||
@ -1542,8 +1542,8 @@ CREATE TABLE public.prices (
|
||||
id integer NOT NULL,
|
||||
group_id integer,
|
||||
plan_id integer,
|
||||
priceable_id integer,
|
||||
priceable_type character varying,
|
||||
priceable_id integer,
|
||||
amount integer,
|
||||
created_at timestamp without time zone NOT NULL,
|
||||
updated_at timestamp without time zone NOT NULL
|
||||
@ -1858,8 +1858,8 @@ CREATE TABLE public.reservations (
|
||||
message text,
|
||||
created_at timestamp without time zone,
|
||||
updated_at timestamp without time zone,
|
||||
reservable_id integer,
|
||||
reservable_type character varying,
|
||||
reservable_id integer,
|
||||
nb_reserve_places integer,
|
||||
statistic_profile_id integer
|
||||
);
|
||||
@ -1891,8 +1891,8 @@ ALTER SEQUENCE public.reservations_id_seq OWNED BY public.reservations.id;
|
||||
CREATE TABLE public.roles (
|
||||
id integer NOT NULL,
|
||||
name character varying,
|
||||
resource_id integer,
|
||||
resource_type character varying,
|
||||
resource_id integer,
|
||||
created_at timestamp without time zone,
|
||||
updated_at timestamp without time zone
|
||||
);
|
||||
@ -2826,8 +2826,8 @@ CREATE TABLE public.users_roles (
|
||||
CREATE TABLE public.wallet_transactions (
|
||||
id integer NOT NULL,
|
||||
wallet_id integer,
|
||||
transactable_id integer,
|
||||
transactable_type character varying,
|
||||
transactable_id integer,
|
||||
transaction_type character varying,
|
||||
amount integer,
|
||||
created_at timestamp without time zone NOT NULL,
|
||||
@ -3871,6 +3871,14 @@ ALTER TABLE ONLY public.roles
|
||||
ADD CONSTRAINT roles_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: schema_migrations schema_migrations_pkey; Type: CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.schema_migrations
|
||||
ADD CONSTRAINT schema_migrations_pkey PRIMARY KEY (version);
|
||||
|
||||
|
||||
--
|
||||
-- Name: settings settings_pkey; Type: CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
@ -4886,29 +4894,6 @@ CREATE INDEX profiles_lower_unaccent_last_name_trgm_idx ON public.profiles USING
|
||||
CREATE INDEX projects_search_vector_idx ON public.projects USING gin (search_vector);
|
||||
|
||||
|
||||
--
|
||||
-- Name: unique_schema_migrations; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE UNIQUE INDEX unique_schema_migrations ON public.schema_migrations USING btree (version);
|
||||
|
||||
|
||||
--
|
||||
-- Name: accounting_periods accounting_periods_del_protect; Type: RULE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE RULE accounting_periods_del_protect AS
|
||||
ON DELETE TO public.accounting_periods DO INSTEAD NOTHING;
|
||||
|
||||
|
||||
--
|
||||
-- Name: accounting_periods accounting_periods_upd_protect; Type: RULE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE RULE accounting_periods_upd_protect AS
|
||||
ON UPDATE TO public.accounting_periods DO INSTEAD NOTHING;
|
||||
|
||||
|
||||
--
|
||||
-- Name: projects projects_search_content_trigger; Type: TRIGGER; Schema: public; Owner: -
|
||||
--
|
||||
@ -5395,7 +5380,6 @@ INSERT INTO "schema_migrations" (version) VALUES
|
||||
('20140605125131'),
|
||||
('20140605142133'),
|
||||
('20140605151442'),
|
||||
('20140606133116'),
|
||||
('20140609092700'),
|
||||
('20140609092827'),
|
||||
('20140610153123'),
|
||||
@ -5464,14 +5448,12 @@ INSERT INTO "schema_migrations" (version) VALUES
|
||||
('20150507075620'),
|
||||
('20150512123546'),
|
||||
('20150520132030'),
|
||||
('20150520133409'),
|
||||
('20150526130729'),
|
||||
('20150527153312'),
|
||||
('20150529113555'),
|
||||
('20150601125944'),
|
||||
('20150603104502'),
|
||||
('20150603104658'),
|
||||
('20150603133050'),
|
||||
('20150604081757'),
|
||||
('20150604131525'),
|
||||
('20150608142234'),
|
||||
@ -5553,7 +5535,6 @@ INSERT INTO "schema_migrations" (version) VALUES
|
||||
('20160905142700'),
|
||||
('20160906094739'),
|
||||
('20160906094847'),
|
||||
('20160906145713'),
|
||||
('20160915105234'),
|
||||
('20161123104604'),
|
||||
('20170109085345'),
|
||||
|
130
setup/upgrade.sh
Normal file
130
setup/upgrade.sh
Normal file
@ -0,0 +1,130 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
parseparams()
|
||||
{
|
||||
COMMANDS=()
|
||||
SCRIPTS=()
|
||||
ENVIRONMENTS=()
|
||||
while getopts "hys:c:e:" opt; do
|
||||
case "${opt}" in
|
||||
y)
|
||||
Y=true
|
||||
;;
|
||||
s)
|
||||
SCRIPTS+=("$OPTARG")
|
||||
;;
|
||||
c)
|
||||
COMMANDS+=("$OPTARG")
|
||||
;;
|
||||
e)
|
||||
ENVIRONMENTS+=("$OPTARG")
|
||||
;;
|
||||
*)
|
||||
usage
|
||||
;;
|
||||
esac
|
||||
done
|
||||
shift $((OPTIND-1))
|
||||
}
|
||||
|
||||
yq() {
|
||||
docker run --rm -i -v "${PWD}:/workdir" mikefarah/yq yq "$@"
|
||||
}
|
||||
|
||||
config()
|
||||
{
|
||||
echo -ne "Checking dependency... "
|
||||
if ! command -v awk || ! [[ $(awk -W version) =~ ^GNU ]]
|
||||
then
|
||||
echo "Please install GNU Awk before running this script."
|
||||
echo "gawk was not found, exiting..."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo -ne "Checking user... "
|
||||
if [[ "$(whoami)" != "root" ]] && ! groups | grep docker
|
||||
then
|
||||
echo "Please add your current user to the docker group OR run this script as root."
|
||||
echo "current user is not allowed to use docker, exiting..."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
SERVICE="$(yq r docker-compose.yml --printMode p 'services.*(.==sleede/fab-manager*)' | awk 'BEGIN { FS = "." } ; {print $2}')"
|
||||
YES_ALL=${Y:-false}
|
||||
# COMMANDS, SCRIPTS and ENVIRONMENTS are set by parseparams
|
||||
}
|
||||
|
||||
add_environments()
|
||||
{
|
||||
for ENV in "${ENVIRONMENTS[@]}"; do
|
||||
if [[ "$ENV" =~ ^[A-Z0-9_]+=.*$ ]]; then
|
||||
printf "# added on %s\n%s\n" "$(date +%Y-%m-%d\ %R)" "$ENV" >> "config/env"
|
||||
else
|
||||
echo "Ignoring invalid option: -e $ENV. Given value is not valid environment variable, please see https://huit.re/environment-doc"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
upgrade()
|
||||
{
|
||||
[[ "$YES_ALL" = "true" ]] && confirm="y" || read -rp "Proceed with the upgrade? (Y/n) " confirm </dev/tty
|
||||
if [[ "$confirm" == "n" ]]; then exit 2; fi
|
||||
|
||||
docker-compose pull "$SERVICE"
|
||||
if [[ $? = 1 ]]; then
|
||||
printf "An error occured, detected service name: %s\nExiting...", "$SERVICE"
|
||||
exit 1
|
||||
fi
|
||||
for SCRIPT in "${SCRIPTS[@]}"; do
|
||||
\curl -sSL "https://raw.githubusercontent.com/sleede/fab-manager/master/scripts/$SCRIPT.sh" | bash
|
||||
done
|
||||
docker-compose down
|
||||
docker-compose run --rm "$SERVICE" bundle exec rake db:migrate
|
||||
rm -rf public/assets
|
||||
docker-compose run --rm "$SERVICE" bundle exec rake assets:precompile
|
||||
for COMMAND in "${COMMANDS[@]}"; do
|
||||
docker-compose run --rm "$SERVICE" bundle exec "$COMMAND"
|
||||
done
|
||||
docker-compose up -d
|
||||
docker ps
|
||||
}
|
||||
|
||||
clean()
|
||||
{
|
||||
echo "Current disk usage:"
|
||||
df -h /
|
||||
[[ "$YES_ALL" = "true" ]] && confirm="y" || read -rp "Clean previous docker images? (y/N) " confirm </dev/tty
|
||||
if [[ "$confirm" == "y" ]]; then
|
||||
/usr/bin/docker image prune -f
|
||||
fi
|
||||
}
|
||||
|
||||
usage()
|
||||
{
|
||||
printf "Usage: %s [OPTIONS]
|
||||
Options:
|
||||
-h Print this message and quit
|
||||
-y Answer yes to all questions
|
||||
-c <string> Provides additional upgrade command, run in the context of the app (TODO DEPLOY)
|
||||
-s <string> Executes a remote script (TODO DEPOY)
|
||||
-e <string> Adds the environment variable to config/env\n" "$(basename "$0")" 1>&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
function trap_ctrlc()
|
||||
{
|
||||
echo "Ctrl^C, exiting..."
|
||||
exit 2
|
||||
}
|
||||
|
||||
proceed()
|
||||
{
|
||||
trap "trap_ctrlc" 2 # SIGINT
|
||||
parseparams "$@"
|
||||
config
|
||||
add_environments
|
||||
upgrade
|
||||
clean
|
||||
}
|
||||
|
||||
proceed "$@"
|
Loading…
x
Reference in New Issue
Block a user