all-dat-base 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/README.md +117 -0
- data/Rakefile +5 -0
- data/all-dat-base.gemspec +39 -0
- data/lib/all-dat-base/version.rb +5 -0
- data/lib/all-dat-base.rb +15 -0
- data/lib/generators/new_base/install/install_generator.rb +201 -0
- metadata +106 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6c2b11162bf07161b5bb121db4a7c677f9b161e75736c3f135a4e3e9e4e502bd
|
4
|
+
data.tar.gz: 032e1731b6a02e5f06568eb6bf1da7a402f67c6ff1879db1f36aedb46bd9bcca
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bbe0d03ee649d8265b3a190977262873208fbf15dd2446ac4a118e028e876b93db161808f982cb546e0af6df588bdd48df7d05b2c18e185568e27bb131dcd58d
|
7
|
+
data.tar.gz: 350b8b76d4180ca77be77d745564d4d25692e7cc226640601ad81be9cc2b36c0c36655af12ce6042a7131dd00afea77313db0691e0a88adefd639ab8bbda2034
|
data/README.md
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
# All About Dat Base 🚀
|
2
|
+
|
3
|
+
A Rails generator that makes connecting your Rails application to Supabase database as easy as running one command!
|
4
|
+
|
5
|
+
## Features
|
6
|
+
|
7
|
+
- 🎯 Interactive environment selection (Development, Production, or Both)
|
8
|
+
- 🔐 Uses Rails encrypted credentials (no dotenv needed)
|
9
|
+
- 📝 Automatically configures `database.yml`
|
10
|
+
- 🎨 Beautiful CLI with arrow key navigation
|
11
|
+
- 📋 Clear step-by-step instructions
|
12
|
+
- 🔄 Preserves multi-database setup for production
|
13
|
+
|
14
|
+
## Installation
|
15
|
+
|
16
|
+
Add this line to your application's Gemfile:
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
gem 'all-about-dat-base'
|
20
|
+
```
|
21
|
+
|
22
|
+
And then execute:
|
23
|
+
|
24
|
+
```bash
|
25
|
+
bundle install
|
26
|
+
```
|
27
|
+
|
28
|
+
## Usage
|
29
|
+
|
30
|
+
Run the generator in your Rails application:
|
31
|
+
|
32
|
+
```bash
|
33
|
+
bin/rails new-base:install
|
34
|
+
```
|
35
|
+
|
36
|
+
The generator will:
|
37
|
+
|
38
|
+
1. **Ask you which environments to configure** - Use arrow keys to select:
|
39
|
+
- Development only
|
40
|
+
- Production only
|
41
|
+
- Both development and production
|
42
|
+
|
43
|
+
2. **Update your `database.yml`** with the appropriate Supabase configuration
|
44
|
+
|
45
|
+
3. **Provide clear instructions** for setting up your Rails credentials
|
46
|
+
|
47
|
+
## What it does
|
48
|
+
|
49
|
+
### Database Configuration
|
50
|
+
|
51
|
+
The generator updates your `config/database.yml` to use Rails credentials:
|
52
|
+
|
53
|
+
```yaml
|
54
|
+
development:
|
55
|
+
<<: *default
|
56
|
+
url: <%= Rails.application.credentials.database_url %>
|
57
|
+
|
58
|
+
production:
|
59
|
+
primary: &primary_production
|
60
|
+
<<: *default
|
61
|
+
url: <%= Rails.application.credentials.database_url %>
|
62
|
+
# ... preserves your multi-database setup
|
63
|
+
```
|
64
|
+
|
65
|
+
### Credentials Setup
|
66
|
+
|
67
|
+
After running the generator, you'll get instructions to:
|
68
|
+
|
69
|
+
1. Edit your Rails credentials:
|
70
|
+
```bash
|
71
|
+
EDITOR="code --wait" rails credentials:edit
|
72
|
+
```
|
73
|
+
|
74
|
+
2. Add your Supabase connection string:
|
75
|
+
```yaml
|
76
|
+
# Database configuration
|
77
|
+
database_url: postgresql://postgres.your-ref:[YOUR-PASSWORD]@aws-0-region.pooler.supabase.com:6543/postgres
|
78
|
+
```
|
79
|
+
|
80
|
+
## Getting Your Supabase Connection String
|
81
|
+
|
82
|
+
1. Go to [Supabase Dashboard](https://supabase.com/dashboard)
|
83
|
+
2. Select your project
|
84
|
+
3. Navigate to: **Settings → Database**
|
85
|
+
4. Find **"Connection string"** section
|
86
|
+
5. Select **"Transaction pooler"** (recommended)
|
87
|
+
6. Copy the connection string
|
88
|
+
|
89
|
+
## Benefits
|
90
|
+
|
91
|
+
- ✅ **No dotenv gem needed** - Uses Rails built-in encrypted credentials
|
92
|
+
- ✅ **Same database everywhere** - Perfect for development with production data
|
93
|
+
- ✅ **Regular Rails commands** - No prefixes needed: `rails g model`, `rails db:migrate`
|
94
|
+
- ✅ **Secure** - Credentials are encrypted and safe for version control
|
95
|
+
- ✅ **Multi-database support** - Preserves your production cache/queue/cable databases
|
96
|
+
|
97
|
+
## Testing Your Setup
|
98
|
+
|
99
|
+
After configuration, test your connection:
|
100
|
+
|
101
|
+
```bash
|
102
|
+
rails db:version
|
103
|
+
rails console
|
104
|
+
# Then: ActiveRecord::Base.connection.execute('SELECT version()').first
|
105
|
+
```
|
106
|
+
|
107
|
+
## Development
|
108
|
+
|
109
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt.
|
110
|
+
|
111
|
+
## Contributing
|
112
|
+
|
113
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/yourusername/all-about-dat-base.
|
114
|
+
|
115
|
+
## License
|
116
|
+
|
117
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/all-dat-base/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "all-dat-base"
|
7
|
+
spec.version = AllDatBase::VERSION
|
8
|
+
spec.authors = ["kungsamu"]
|
9
|
+
spec.email = ["skung89@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = "Rails generator for easy Supabase database configuration"
|
12
|
+
spec.description = "A Rails generator that provides interactive setup for Supabase database configuration with environment selection and credential management."
|
13
|
+
spec.homepage = "https://github.com/thebaowarrior/all-dat-base-gem"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.required_ruby_version = ">= 3.0.0"
|
16
|
+
|
17
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
18
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
19
|
+
spec.metadata["changelog_uri"] = "#{spec.homepage}/blob/main/CHANGELOG.md"
|
20
|
+
|
21
|
+
# Specify which files should be added to the gem when it is released.
|
22
|
+
spec.files = Dir.chdir(__dir__) do
|
23
|
+
`git ls-files -z 2>/dev/null`.split("\x0").reject do |f|
|
24
|
+
(File.expand_path(f) == __FILE__) ||
|
25
|
+
f.start_with?(*%w[bin/ test/ spec/ features/ .git .github appveyor Gemfile])
|
26
|
+
end
|
27
|
+
end
|
28
|
+
spec.bindir = "exe"
|
29
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ["lib"]
|
31
|
+
|
32
|
+
# Dependencies
|
33
|
+
spec.add_dependency "rails", ">= 6.0"
|
34
|
+
spec.add_dependency "tty-prompt", "~> 0.23"
|
35
|
+
|
36
|
+
# Development dependencies
|
37
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
38
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
39
|
+
end
|
data/lib/all-dat-base.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "all-dat-base/version"
|
4
|
+
|
5
|
+
module AllDatBase
|
6
|
+
class Error < StandardError; end
|
7
|
+
|
8
|
+
# Main module for the All Dat Base gem
|
9
|
+
# Provides Rails generators for Supabase database configuration
|
10
|
+
end
|
11
|
+
|
12
|
+
# Load Rails generators if Rails is available
|
13
|
+
if defined?(Rails)
|
14
|
+
require_relative "generators/new_base/install/install_generator"
|
15
|
+
end
|
@@ -0,0 +1,201 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails/generators'
|
4
|
+
require 'tty-prompt'
|
5
|
+
|
6
|
+
module NewBase
|
7
|
+
module Generators
|
8
|
+
class InstallGenerator < Rails::Generators::Base
|
9
|
+
desc "Configure your Rails application to use Supabase database"
|
10
|
+
|
11
|
+
source_root File.expand_path('templates', __dir__)
|
12
|
+
|
13
|
+
def install_supabase_config
|
14
|
+
say "🚀 Welcome to All About Dat Base - Supabase Configuration Generator!", :green
|
15
|
+
say ""
|
16
|
+
|
17
|
+
# Interactive environment selection
|
18
|
+
prompt = TTY::Prompt.new
|
19
|
+
|
20
|
+
environment_choice = prompt.select(
|
21
|
+
"Which environments do you want to configure for Supabase?",
|
22
|
+
[
|
23
|
+
{ name: "Development only", value: :development },
|
24
|
+
{ name: "Production only", value: :production },
|
25
|
+
{ name: "Both development and production", value: :both }
|
26
|
+
],
|
27
|
+
symbols: { marker: "❯" }
|
28
|
+
)
|
29
|
+
|
30
|
+
say ""
|
31
|
+
say "📝 Configuring database.yml for #{environment_choice}...", :blue
|
32
|
+
|
33
|
+
# Generate database.yml based on selection
|
34
|
+
generate_database_config(environment_choice)
|
35
|
+
|
36
|
+
say ""
|
37
|
+
say "✅ Database configuration updated!", :green
|
38
|
+
say ""
|
39
|
+
|
40
|
+
# Provide credentials instructions
|
41
|
+
show_credentials_instructions
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def generate_database_config(environment_choice)
|
47
|
+
# Read existing database.yml or create new one
|
48
|
+
database_yml_path = Rails.root.join('config', 'database.yml')
|
49
|
+
|
50
|
+
if File.exist?(database_yml_path)
|
51
|
+
say "📄 Backing up existing database.yml to database.yml.backup", :yellow
|
52
|
+
FileUtils.cp(database_yml_path, "#{database_yml_path}.backup")
|
53
|
+
end
|
54
|
+
|
55
|
+
# Generate new database.yml
|
56
|
+
template_content = generate_database_yml_content(environment_choice)
|
57
|
+
|
58
|
+
File.write(database_yml_path, template_content)
|
59
|
+
say "📝 Updated config/database.yml", :green
|
60
|
+
end
|
61
|
+
|
62
|
+
def generate_database_yml_content(environment_choice)
|
63
|
+
content = <<~YAML
|
64
|
+
# PostgreSQL configuration for Supabase
|
65
|
+
# Generated by All About Dat Base gem
|
66
|
+
|
67
|
+
default: &default
|
68
|
+
adapter: postgresql
|
69
|
+
encoding: unicode
|
70
|
+
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
|
71
|
+
|
72
|
+
YAML
|
73
|
+
|
74
|
+
case environment_choice
|
75
|
+
when :development
|
76
|
+
content += development_config + test_config_local + production_config_local
|
77
|
+
when :production
|
78
|
+
content += development_config_local + test_config_local + production_config
|
79
|
+
when :both
|
80
|
+
content += development_config + test_config + production_config
|
81
|
+
end
|
82
|
+
|
83
|
+
content
|
84
|
+
end
|
85
|
+
|
86
|
+
def development_config
|
87
|
+
<<~YAML
|
88
|
+
development:
|
89
|
+
<<: *default
|
90
|
+
url: <%= Rails.application.credentials.database_url %>
|
91
|
+
|
92
|
+
YAML
|
93
|
+
end
|
94
|
+
|
95
|
+
def development_config_local
|
96
|
+
<<~YAML
|
97
|
+
development:
|
98
|
+
<<: *default
|
99
|
+
database: #{Rails.application.class.module_parent_name.underscore}_development
|
100
|
+
|
101
|
+
YAML
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_config
|
105
|
+
<<~YAML
|
106
|
+
test:
|
107
|
+
<<: *default
|
108
|
+
url: <%= Rails.application.credentials.database_url %>
|
109
|
+
|
110
|
+
YAML
|
111
|
+
end
|
112
|
+
|
113
|
+
def test_config_local
|
114
|
+
<<~YAML
|
115
|
+
test:
|
116
|
+
<<: *default
|
117
|
+
database: #{Rails.application.class.module_parent_name.underscore}_test
|
118
|
+
|
119
|
+
YAML
|
120
|
+
end
|
121
|
+
|
122
|
+
def production_config
|
123
|
+
<<~YAML
|
124
|
+
production:
|
125
|
+
primary: &primary_production
|
126
|
+
<<: *default
|
127
|
+
url: <%= Rails.application.credentials.database_url %>
|
128
|
+
cache:
|
129
|
+
<<: *primary_production
|
130
|
+
database: #{Rails.application.class.module_parent_name.underscore}_production_cache
|
131
|
+
migrations_paths: db/cache_migrate
|
132
|
+
queue:
|
133
|
+
<<: *primary_production
|
134
|
+
database: #{Rails.application.class.module_parent_name.underscore}_production_queue
|
135
|
+
migrations_paths: db/queue_migrate
|
136
|
+
cable:
|
137
|
+
<<: *primary_production
|
138
|
+
database: #{Rails.application.class.module_parent_name.underscore}_production_cable
|
139
|
+
migrations_paths: db/cable_migrate
|
140
|
+
YAML
|
141
|
+
end
|
142
|
+
|
143
|
+
def production_config_local
|
144
|
+
<<~YAML
|
145
|
+
production:
|
146
|
+
primary: &primary_production
|
147
|
+
<<: *default
|
148
|
+
database: #{Rails.application.class.module_parent_name.underscore}_production
|
149
|
+
username: #{Rails.application.class.module_parent_name.underscore}
|
150
|
+
password: <%= ENV["#{Rails.application.class.module_parent_name.underscore.upcase}_DATABASE_PASSWORD"] %>
|
151
|
+
cache:
|
152
|
+
<<: *primary_production
|
153
|
+
database: #{Rails.application.class.module_parent_name.underscore}_production_cache
|
154
|
+
migrations_paths: db/cache_migrate
|
155
|
+
queue:
|
156
|
+
<<: *primary_production
|
157
|
+
database: #{Rails.application.class.module_parent_name.underscore}_production_queue
|
158
|
+
migrations_paths: db/queue_migrate
|
159
|
+
cable:
|
160
|
+
<<: *primary_production
|
161
|
+
database: #{Rails.application.class.module_parent_name.underscore}_production_cable
|
162
|
+
migrations_paths: db/cable_migrate
|
163
|
+
YAML
|
164
|
+
end
|
165
|
+
|
166
|
+
def show_credentials_instructions
|
167
|
+
say "🔐 NEXT STEP: Configure your Rails credentials", :cyan
|
168
|
+
say "=" * 60, :cyan
|
169
|
+
say ""
|
170
|
+
say "1. Run this command to edit your Rails credentials:", :white
|
171
|
+
say ""
|
172
|
+
say " EDITOR=\"code --wait\" rails credentials:edit", :yellow
|
173
|
+
say ""
|
174
|
+
say "2. Copy and paste this into your credentials file:", :white
|
175
|
+
say ""
|
176
|
+
say " # Database configuration", :green
|
177
|
+
say " database_url: postgresql://postgres.clwfpjefrgrnzqnaxnlk:[YOUR-PASSWORD]@aws-1-ap-southeast-1.pooler.supabase.com:6543/postgres", :green
|
178
|
+
say ""
|
179
|
+
say "3. Replace [YOUR-PASSWORD] with your actual Supabase password", :white
|
180
|
+
say ""
|
181
|
+
say "4. Make sure to URL-encode special characters in your password:", :white
|
182
|
+
say " @ becomes %40", :yellow
|
183
|
+
say " # becomes %23", :yellow
|
184
|
+
say " & becomes %26", :yellow
|
185
|
+
say ""
|
186
|
+
say "5. Get your connection string from:", :white
|
187
|
+
say " • Supabase Dashboard → Settings → Database", :blue
|
188
|
+
say " • Select 'Transaction pooler' (recommended)", :blue
|
189
|
+
say ""
|
190
|
+
say "6. Test your connection:", :white
|
191
|
+
say " rails db:version", :yellow
|
192
|
+
say ""
|
193
|
+
say "🎉 You're all set! Your Rails app is now configured for Supabase!", :green
|
194
|
+
say "=" * 60, :cyan
|
195
|
+
say ""
|
196
|
+
say "💡 Pro tip: You can run this generator again anytime with:", :blue
|
197
|
+
say " bin/rails generate new_base:install", :yellow
|
198
|
+
end
|
199
|
+
end
|
200
|
+
end
|
201
|
+
end
|
metadata
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: all-dat-base
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- kungsamu
|
8
|
+
bindir: exe
|
9
|
+
cert_chain: []
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
11
|
+
dependencies:
|
12
|
+
- !ruby/object:Gem::Dependency
|
13
|
+
name: rails
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - ">="
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: '6.0'
|
19
|
+
type: :runtime
|
20
|
+
prerelease: false
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
requirements:
|
23
|
+
- - ">="
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: '6.0'
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: tty-prompt
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - "~>"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0.23'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0.23'
|
40
|
+
- !ruby/object:Gem::Dependency
|
41
|
+
name: bundler
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '2.0'
|
47
|
+
type: :development
|
48
|
+
prerelease: false
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '2.0'
|
54
|
+
- !ruby/object:Gem::Dependency
|
55
|
+
name: rake
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '13.0'
|
61
|
+
type: :development
|
62
|
+
prerelease: false
|
63
|
+
version_requirements: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '13.0'
|
68
|
+
description: A Rails generator that provides interactive setup for Supabase database
|
69
|
+
configuration with environment selection and credential management.
|
70
|
+
email:
|
71
|
+
- skung89@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- README.md
|
77
|
+
- Rakefile
|
78
|
+
- all-dat-base.gemspec
|
79
|
+
- lib/all-dat-base.rb
|
80
|
+
- lib/all-dat-base/version.rb
|
81
|
+
- lib/generators/new_base/install/install_generator.rb
|
82
|
+
homepage: https://github.com/thebaowarrior/all-dat-base-gem
|
83
|
+
licenses:
|
84
|
+
- MIT
|
85
|
+
metadata:
|
86
|
+
homepage_uri: https://github.com/thebaowarrior/all-dat-base-gem
|
87
|
+
source_code_uri: https://github.com/thebaowarrior/all-dat-base-gem
|
88
|
+
changelog_uri: https://github.com/thebaowarrior/all-dat-base-gem/blob/main/CHANGELOG.md
|
89
|
+
rdoc_options: []
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 3.0.0
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
requirements: []
|
103
|
+
rubygems_version: 3.7.1
|
104
|
+
specification_version: 4
|
105
|
+
summary: Rails generator for easy Supabase database configuration
|
106
|
+
test_files: []
|