-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup_dv4.sh
144 lines (126 loc) · 3.87 KB
/
setup_dv4.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/bin/bash
set -e # Exit on any error
# Variables
APP_NAME="dv4"
LEGACY_APP="dv"
DB_NAME="dv4_development"
DB_USER="postgres"
DB_PASS="password"
RUBY_VERSION="3.2.2"
NODE_VERSION="18"
YARN_VERSION="latest"
# # Step 1: Install dependencies (if needed)
# echo "Installing required dependencies..."
# if [[ "$OSTYPE" == "darwin"* ]]; then
# # macOS specific installation
# brew update
# brew install curl git node@$NODE_VERSION yarn postgresql@16 rbenv ruby-build
# brew services start postgresql@16
# # Setup rbenv and install Ruby
# eval "$(rbenv init -)"
# rbenv install -s $RUBY_VERSION
# rbenv global $RUBY_VERSION
# gem install bundler
# else
# # Linux installation
# sudo apt update
# sudo apt install -y curl git nodejs yarn postgresql postgresql-contrib libpq-dev build-essential libssl-dev zlib1g-dev \
# libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev software-properties-common \
# libffi-dev ruby-dev rbenv ruby-build
# # Setup rbenv and install Ruby
# eval "$(rbenv init -)"
# rbenv install -s $RUBY_VERSION
# rbenv global $RUBY_VERSION
# gem install bundler
# fi
# # Step 2: Setup PostgreSQL
# echo "Setting up PostgreSQL..."
# if [[ "$OSTYPE" == "darwin"* ]]; then
# createuser -s $DB_USER || true
# createdb $DB_NAME -O $DB_USER
# else
# sudo -u postgres psql -c "CREATE USER $DB_USER WITH PASSWORD '$DB_PASS';"
# sudo -u postgres psql -c "CREATE DATABASE $DB_NAME OWNER $DB_USER;"
# sudo -u postgres psql -c "ALTER USER $DB_USER CREATEDB;"
# fi
# # Step 3: Create a new Rails 7 application
# echo "Creating new Rails 7 application: $APP_NAME..."
# gem install rails -v 7.0.4
# rails new $APP_NAME -d postgresql --skip-javascript --skip-turbolinks
# cd $APP_NAME
# # Step 4: Configure database connection
# cat <<EOL > config/database.yml
# default: &default
# adapter: postgresql
# encoding: unicode
# pool: 5
# username: $DB_USER
# password: $DB_PASS
# host: localhost
# development:
# <<: *default
# database: $DB_NAME
# test:
# <<: *default
# database: ${DB_NAME}_test
# production:
# <<: *default
# database: ${DB_NAME}_production
# EOL
# # Step 5: Install gems (Replace Gemfile with necessary gems)
# echo "Updating Gemfile..."
# cat <<EOL > Gemfile
# source "https://rubygems.org"
# gem "rails", "7.0.4"
# gem "pg"
# gem "sassc-rails"
# gem "jquery-rails"
# gem "devise"
# gem "ckeditor"
# gem "font-awesome-rails"
# gem "jquery-ui-rails"
# gem "thinking-sphinx"
# gem "bootstrap"
# gem "tabler-rubygem"
# gem "diffy"
# gem "will_paginate"
# gem "rails-html-sanitizer"
# gem "jwt"
# gem "rack-cors"
# gem "docx_replace"
# gem "roo"
# gem "rqrcode"
# gem "x-editable-rails"
# gem "sidekiq"
# gem "redis"
# gem "hiredis"
# gem "httparty"
# gem "savon"
# group :development, :test do
# gem "byebug"
# end
# group :development do
# gem "web-console"
# gem "spring"
# end
# EOL
# bundle install
# # Step 6: Run migrations
# echo "Running database migrations..."
# cp /mnt/data/20250125200134_create_all_tables.rb db/migrate/
# cp /mnt/data/20250125200134_add_indexes_to_tables.rb db/migrate/
rails db:migrate
# Step 7: Copy files from legacy Rails app
echo "Copying necessary files from legacy app ($LEGACY_APP) to new app ($APP_NAME)..."
rsync -av --progress ../$LEGACY_APP/app/models/ app/models/
rsync -av --progress ../$LEGACY_APP/app/controllers/ app/controllers/
rsync -av --progress ../$LEGACY_APP/app/views/ app/views/
rsync -av --progress ../$LEGACY_APP/app/services/ app/services/
rsync -av --progress ../$LEGACY_APP/app/jobs/ app/jobs/
rsync -av --progress ../$LEGACY_APP/app/helpers/ app/helpers/
rsync -av --progress ../$LEGACY_APP/app/assets/ app/assets/
rsync -av --progress ../$LEGACY_APP/lib/ lib/
rsync -av --progress ../$LEGACY_APP/config/locales/ config/locales/
# Step 8: Cleanup and Final Steps
echo "Setup complete! Start the server with:"
echo "cd $APP_NAME && rails server"