database-model-generator 0.6.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
- checksums.yaml.gz.sig +3 -0
- data/CHANGES.md +59 -0
- data/Gemfile +2 -0
- data/LICENSE +177 -0
- data/MANIFEST.md +10 -0
- data/README.md +186 -0
- data/Rakefile +32 -0
- data/bin/dmg +831 -0
- data/certs/djberg96_pub.pem +26 -0
- data/database-model-generator.gemspec +31 -0
- data/docker/README.md +238 -0
- data/docker/oracle/Dockerfile +87 -0
- data/docker/oracle/README.md +140 -0
- data/docker/oracle/docker-compose.yml +41 -0
- data/docker/oracle/test.sh +45 -0
- data/docker/sqlserver/DOCKER.md +152 -0
- data/docker/sqlserver/Dockerfile +29 -0
- data/docker/sqlserver/SUPPORT.md +477 -0
- data/docker/sqlserver/TESTING.md +194 -0
- data/docker/sqlserver/docker-compose.yml +52 -0
- data/docker/sqlserver/init-db.sql +158 -0
- data/docker/sqlserver/run_tests.sh +154 -0
- data/docker/sqlserver/setup-db.sh +9 -0
- data/docker/sqlserver/test-Dockerfile +36 -0
- data/docker/sqlserver/test.sh +56 -0
- data/lib/database_model_generator.rb +652 -0
- data/lib/oracle/model/generator.rb +287 -0
- data/lib/sqlserver/model/generator.rb +281 -0
- data/spec/oracle_model_generator_spec.rb +176 -0
- data/spec/spec_helper.rb +30 -0
- data/spec/support/oracle_connection.rb +126 -0
- data.tar.gz.sig +0 -0
- metadata +162 -0
- metadata.gz.sig +0 -0
@@ -0,0 +1,194 @@
|
|
1
|
+
# SQL Server Docker Testing Guide
|
2
|
+
|
3
|
+
## 🚀 Quick Test
|
4
|
+
|
5
|
+
To quickly test SQL Server support with Docker:
|
6
|
+
|
7
|
+
```bash
|
8
|
+
./test_sqlserver_simple.sh
|
9
|
+
```
|
10
|
+
|
11
|
+
This will automatically:
|
12
|
+
1. ✅ Pull and start SQL Server 2022 Express
|
13
|
+
2. ✅ Create test database with sample tables
|
14
|
+
3. ✅ Test model generation with various scenarios
|
15
|
+
4. ✅ Show generated Ruby code
|
16
|
+
5. ✅ Clean up containers when done
|
17
|
+
|
18
|
+
## 📋 What Gets Tested
|
19
|
+
|
20
|
+
### Model Generation
|
21
|
+
- **Users model** with RSpec tests
|
22
|
+
- **Posts model** with foreign key relationships
|
23
|
+
- **Auto-detection** of SQL Server when `-s` parameter is used
|
24
|
+
|
25
|
+
### Index Recommendations
|
26
|
+
- Foreign key indexes
|
27
|
+
- Unique constraint indexes
|
28
|
+
- Date query indexes
|
29
|
+
- Status/enum indexes
|
30
|
+
- Composite indexes
|
31
|
+
- Full-text search recommendations
|
32
|
+
|
33
|
+
### Test Framework Support
|
34
|
+
- **RSpec** test generation
|
35
|
+
- **Minitest** test generation
|
36
|
+
- **TestUnit** test generation
|
37
|
+
|
38
|
+
## 🔧 Manual Testing
|
39
|
+
|
40
|
+
If you prefer manual control:
|
41
|
+
|
42
|
+
```bash
|
43
|
+
# 1. Start SQL Server
|
44
|
+
docker run -d --name sqlserver_test \
|
45
|
+
-e "ACCEPT_EULA=Y" \
|
46
|
+
-e "SA_PASSWORD=YourStrong!Passw0rd" \
|
47
|
+
-e "MSSQL_PID=Express" \
|
48
|
+
-p 1433:1433 \
|
49
|
+
mcr.microsoft.com/mssql/server:2022-latest
|
50
|
+
|
51
|
+
# 2. Wait for startup (60 seconds)
|
52
|
+
sleep 60
|
53
|
+
|
54
|
+
# 3. Create test database
|
55
|
+
docker exec sqlserver_test /opt/mssql-tools/bin/sqlcmd \
|
56
|
+
-S localhost -U sa -P YourStrong!Passw0rd \
|
57
|
+
-Q "CREATE DATABASE test_db"
|
58
|
+
|
59
|
+
# 4. Test the generator
|
60
|
+
ruby bin/dmg -T sqlserver -s localhost -P 1433 -d test_db \
|
61
|
+
-u sa -p 'YourStrong!Passw0rd' -t sys.tables -x rspec
|
62
|
+
|
63
|
+
# 5. Clean up
|
64
|
+
docker stop sqlserver_test && docker rm sqlserver_test
|
65
|
+
```
|
66
|
+
|
67
|
+
## 📊 Sample Database Schema
|
68
|
+
|
69
|
+
The test creates realistic tables:
|
70
|
+
|
71
|
+
- **users** - User accounts with various data types
|
72
|
+
- **posts** - Blog posts with foreign keys to users
|
73
|
+
- **categories** - Hierarchical categories
|
74
|
+
- **post_categories** - Many-to-many junction table
|
75
|
+
- **comments** - Comments linking posts and users
|
76
|
+
|
77
|
+
## 🎯 Expected Results
|
78
|
+
|
79
|
+
### Generated User Model Example
|
80
|
+
```ruby
|
81
|
+
# Generated by Database Model Generator v0.6.0
|
82
|
+
class User < ActiveRecord::Base
|
83
|
+
set_table_name "users"
|
84
|
+
set_primary_key :id
|
85
|
+
|
86
|
+
# Table relationships
|
87
|
+
has_many :posts, class_name: 'Post'
|
88
|
+
has_many :comments, class_name: 'Comment'
|
89
|
+
|
90
|
+
# Scopes
|
91
|
+
scope :active, -> { where(status: 'active') }
|
92
|
+
scope :recent, -> { where('created_at > ?', 30.days.ago) }
|
93
|
+
|
94
|
+
# Validations
|
95
|
+
validates :username, length: {maximum: 50}, presence: true
|
96
|
+
validates :email, length: {maximum: 100}, presence: true
|
97
|
+
validates :first_name, length: {maximum: 50}, presence: true
|
98
|
+
# ... more validations
|
99
|
+
end
|
100
|
+
```
|
101
|
+
|
102
|
+
### Index Recommendations Example
|
103
|
+
```
|
104
|
+
Foreign Keys:
|
105
|
+
add_index :posts, :user_id
|
106
|
+
|
107
|
+
Unique Constraints:
|
108
|
+
add_index :users, :username, unique: true
|
109
|
+
add_index :users, :email, unique: true
|
110
|
+
|
111
|
+
Date Queries:
|
112
|
+
add_index :users, :created_at
|
113
|
+
add_index :posts, :published_at
|
114
|
+
|
115
|
+
Composite:
|
116
|
+
add_index :posts, [:user_id, :created_at]
|
117
|
+
```
|
118
|
+
|
119
|
+
## 🔍 Verification Steps
|
120
|
+
|
121
|
+
The test script verifies:
|
122
|
+
|
123
|
+
1. **Docker availability** and SQL Server startup
|
124
|
+
2. **Database connectivity** using tiny_tds gem
|
125
|
+
3. **Model generation** with proper ActiveRecord syntax
|
126
|
+
4. **Test file creation** with chosen framework
|
127
|
+
5. **Index recommendations** based on table analysis
|
128
|
+
6. **Auto-detection** when server parameter provided
|
129
|
+
7. **Foreign key mapping** to belongs_to/has_many relationships
|
130
|
+
|
131
|
+
## 🛠️ Prerequisites
|
132
|
+
|
133
|
+
- **Docker** installed and running
|
134
|
+
- **Ruby** 2.7+ with bundler
|
135
|
+
- **tiny_tds gem** (auto-installed by test script)
|
136
|
+
|
137
|
+
## 🚨 Troubleshooting
|
138
|
+
|
139
|
+
### SQL Server Startup Issues
|
140
|
+
- **Wait longer**: SQL Server can take 2-3 minutes to start
|
141
|
+
- **Check logs**: `docker logs sqlserver_test`
|
142
|
+
- **Port conflicts**: Ensure port 1433 is available
|
143
|
+
|
144
|
+
### Connection Issues
|
145
|
+
- **Password complexity**: Must meet SQL Server requirements
|
146
|
+
- **Firewall**: Check local firewall settings
|
147
|
+
- **Container status**: Verify container is running and healthy
|
148
|
+
|
149
|
+
### Gem Installation
|
150
|
+
```bash
|
151
|
+
# Ubuntu/Debian
|
152
|
+
sudo apt-get install build-essential freetds-dev
|
153
|
+
gem install tiny_tds
|
154
|
+
|
155
|
+
# macOS
|
156
|
+
brew install freetds
|
157
|
+
gem install tiny_tds
|
158
|
+
```
|
159
|
+
|
160
|
+
## 📁 File Structure
|
161
|
+
|
162
|
+
```
|
163
|
+
docker/
|
164
|
+
├── README.md # This documentation
|
165
|
+
├── sqlserver/
|
166
|
+
│ ├── Dockerfile # SQL Server container
|
167
|
+
│ ├── init-db.sql # Database setup script
|
168
|
+
│ └── setup-db.sh # Automation script
|
169
|
+
└── test/
|
170
|
+
├── Dockerfile # Test runner container
|
171
|
+
└── run_tests.sh # Test suite
|
172
|
+
|
173
|
+
docker-compose.sqlserver.yml # Docker Compose config
|
174
|
+
test_sqlserver_simple.sh # Simple test script ⭐
|
175
|
+
test_sqlserver_docker.sh # Advanced test script
|
176
|
+
```
|
177
|
+
|
178
|
+
## 🎉 Success Indicators
|
179
|
+
|
180
|
+
When everything works correctly, you'll see:
|
181
|
+
|
182
|
+
```
|
183
|
+
✅ Docker is available
|
184
|
+
✅ SQL Server container started
|
185
|
+
✅ SQL Server is ready!
|
186
|
+
✅ Test database created with sample data
|
187
|
+
✅ tiny_tds gem is available
|
188
|
+
✅ User model generated successfully!
|
189
|
+
✅ Auto-detection successful!
|
190
|
+
✅ Direct connection successful! Found 2 users
|
191
|
+
✅ All tests completed successfully!
|
192
|
+
```
|
193
|
+
|
194
|
+
The generated Ruby models will demonstrate that your Database Model Generator now fully supports SQL Server alongside Oracle! 🎊
|
@@ -0,0 +1,52 @@
|
|
1
|
+
services:
|
2
|
+
sqlserver:
|
3
|
+
build:
|
4
|
+
context: ../../
|
5
|
+
dockerfile: docker/sqlserver/Dockerfile
|
6
|
+
container_name: omg_sqlserver
|
7
|
+
ports:
|
8
|
+
- "1433:1433"
|
9
|
+
environment:
|
10
|
+
- ACCEPT_EULA=Y
|
11
|
+
- SA_PASSWORD=YourStrong!Passw0rd
|
12
|
+
- MSSQL_PID=Express
|
13
|
+
volumes:
|
14
|
+
- sqlserver_data:/var/opt/mssql
|
15
|
+
healthcheck:
|
16
|
+
test: ["CMD-SHELL", "/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P YourStrong!Passw0rd -Q 'SELECT 1'"]
|
17
|
+
interval: 30s
|
18
|
+
timeout: 10s
|
19
|
+
retries: 5
|
20
|
+
start_period: 60s
|
21
|
+
networks:
|
22
|
+
- omg_network
|
23
|
+
|
24
|
+
# Optional: Add a container to test the generator
|
25
|
+
omg_test:
|
26
|
+
build:
|
27
|
+
context: ../../
|
28
|
+
dockerfile: docker/test/Dockerfile
|
29
|
+
container_name: omg_test_runner
|
30
|
+
depends_on:
|
31
|
+
sqlserver:
|
32
|
+
condition: service_healthy
|
33
|
+
volumes:
|
34
|
+
- ../../:/app
|
35
|
+
- /app/vendor
|
36
|
+
working_dir: /app
|
37
|
+
environment:
|
38
|
+
- SQLSERVER_HOST=sqlserver
|
39
|
+
- SQLSERVER_PORT=1433
|
40
|
+
- SQLSERVER_USERNAME=sa
|
41
|
+
- SQLSERVER_PASSWORD=YourStrong!Passw0rd
|
42
|
+
- SQLSERVER_DATABASE=test_db
|
43
|
+
networks:
|
44
|
+
- omg_network
|
45
|
+
command: ["./docker/test/run_tests.sh"]
|
46
|
+
|
47
|
+
volumes:
|
48
|
+
sqlserver_data:
|
49
|
+
|
50
|
+
networks:
|
51
|
+
omg_network:
|
52
|
+
driver: bridge
|
@@ -0,0 +1,158 @@
|
|
1
|
+
-- SQL Server Database Initialization Script
|
2
|
+
-- Creates a test database and sample tables for the Database Model Generator
|
3
|
+
|
4
|
+
-- Create test database
|
5
|
+
IF NOT EXISTS (SELECT name FROM sys.databases WHERE name = 'test_db')
|
6
|
+
BEGIN
|
7
|
+
CREATE DATABASE test_db;
|
8
|
+
END
|
9
|
+
GO
|
10
|
+
|
11
|
+
USE test_db;
|
12
|
+
GO
|
13
|
+
|
14
|
+
-- Create users table with various column types
|
15
|
+
IF NOT EXISTS (SELECT * FROM sysobjects WHERE name='users' AND xtype='U')
|
16
|
+
BEGIN
|
17
|
+
CREATE TABLE users (
|
18
|
+
id INT IDENTITY(1,1) PRIMARY KEY,
|
19
|
+
username NVARCHAR(50) NOT NULL UNIQUE,
|
20
|
+
email NVARCHAR(100) NOT NULL UNIQUE,
|
21
|
+
first_name NVARCHAR(50) NOT NULL,
|
22
|
+
last_name NVARCHAR(50) NOT NULL,
|
23
|
+
age INT,
|
24
|
+
salary DECIMAL(10,2),
|
25
|
+
is_active BIT DEFAULT 1,
|
26
|
+
status NVARCHAR(20) DEFAULT 'active',
|
27
|
+
created_at DATETIME2 DEFAULT GETDATE(),
|
28
|
+
updated_at DATETIME2 DEFAULT GETDATE(),
|
29
|
+
bio NVARCHAR(MAX),
|
30
|
+
profile_picture VARBINARY(MAX)
|
31
|
+
);
|
32
|
+
END
|
33
|
+
GO
|
34
|
+
|
35
|
+
-- Create posts table with foreign key relationship
|
36
|
+
IF NOT EXISTS (SELECT * FROM sysobjects WHERE name='posts' AND xtype='U')
|
37
|
+
BEGIN
|
38
|
+
CREATE TABLE posts (
|
39
|
+
id INT IDENTITY(1,1) PRIMARY KEY,
|
40
|
+
user_id INT NOT NULL,
|
41
|
+
title NVARCHAR(200) NOT NULL,
|
42
|
+
content NVARCHAR(MAX),
|
43
|
+
status NVARCHAR(20) DEFAULT 'draft',
|
44
|
+
published_at DATETIME2,
|
45
|
+
created_at DATETIME2 DEFAULT GETDATE(),
|
46
|
+
updated_at DATETIME2 DEFAULT GETDATE(),
|
47
|
+
view_count INT DEFAULT 0,
|
48
|
+
is_featured BIT DEFAULT 0,
|
49
|
+
|
50
|
+
CONSTRAINT FK_posts_user_id FOREIGN KEY (user_id) REFERENCES users(id)
|
51
|
+
);
|
52
|
+
END
|
53
|
+
GO
|
54
|
+
|
55
|
+
-- Create categories table
|
56
|
+
IF NOT EXISTS (SELECT * FROM sysobjects WHERE name='categories' AND xtype='U')
|
57
|
+
BEGIN
|
58
|
+
CREATE TABLE categories (
|
59
|
+
id INT IDENTITY(1,1) PRIMARY KEY,
|
60
|
+
name NVARCHAR(100) NOT NULL UNIQUE,
|
61
|
+
description NVARCHAR(500),
|
62
|
+
slug NVARCHAR(100) NOT NULL UNIQUE,
|
63
|
+
parent_id INT,
|
64
|
+
is_active BIT DEFAULT 1,
|
65
|
+
created_at DATETIME2 DEFAULT GETDATE(),
|
66
|
+
|
67
|
+
CONSTRAINT FK_categories_parent FOREIGN KEY (parent_id) REFERENCES categories(id)
|
68
|
+
);
|
69
|
+
END
|
70
|
+
GO
|
71
|
+
|
72
|
+
-- Create post_categories junction table
|
73
|
+
IF NOT EXISTS (SELECT * FROM sysobjects WHERE name='post_categories' AND xtype='U')
|
74
|
+
BEGIN
|
75
|
+
CREATE TABLE post_categories (
|
76
|
+
id INT IDENTITY(1,1) PRIMARY KEY,
|
77
|
+
post_id INT NOT NULL,
|
78
|
+
category_id INT NOT NULL,
|
79
|
+
created_at DATETIME2 DEFAULT GETDATE(),
|
80
|
+
|
81
|
+
CONSTRAINT FK_post_categories_post FOREIGN KEY (post_id) REFERENCES posts(id),
|
82
|
+
CONSTRAINT FK_post_categories_category FOREIGN KEY (category_id) REFERENCES categories(id),
|
83
|
+
CONSTRAINT UQ_post_categories UNIQUE (post_id, category_id)
|
84
|
+
);
|
85
|
+
END
|
86
|
+
GO
|
87
|
+
|
88
|
+
-- Create comments table
|
89
|
+
IF NOT EXISTS (SELECT * FROM sysobjects WHERE name='comments' AND xtype='U')
|
90
|
+
BEGIN
|
91
|
+
CREATE TABLE comments (
|
92
|
+
id INT IDENTITY(1,1) PRIMARY KEY,
|
93
|
+
post_id INT NOT NULL,
|
94
|
+
user_id INT NOT NULL,
|
95
|
+
content NVARCHAR(MAX) NOT NULL,
|
96
|
+
status NVARCHAR(20) DEFAULT 'pending',
|
97
|
+
created_at DATETIME2 DEFAULT GETDATE(),
|
98
|
+
updated_at DATETIME2 DEFAULT GETDATE(),
|
99
|
+
|
100
|
+
CONSTRAINT FK_comments_post FOREIGN KEY (post_id) REFERENCES posts(id),
|
101
|
+
CONSTRAINT FK_comments_user FOREIGN KEY (user_id) REFERENCES users(id)
|
102
|
+
);
|
103
|
+
END
|
104
|
+
GO
|
105
|
+
|
106
|
+
-- Insert sample data
|
107
|
+
INSERT INTO users (username, email, first_name, last_name, age, salary, status, bio)
|
108
|
+
VALUES
|
109
|
+
('jdoe', 'john.doe@example.com', 'John', 'Doe', 30, 75000.00, 'active', 'Software developer with 5 years experience'),
|
110
|
+
('asmith', 'alice.smith@example.com', 'Alice', 'Smith', 28, 82000.00, 'active', 'Frontend specialist and UI/UX designer'),
|
111
|
+
('bwilson', 'bob.wilson@example.com', 'Bob', 'Wilson', 35, 95000.00, 'active', 'Senior backend engineer'),
|
112
|
+
('cmiller', 'carol.miller@example.com', 'Carol', 'Miller', 32, 88000.00, 'inactive', 'Database administrator');
|
113
|
+
GO
|
114
|
+
|
115
|
+
INSERT INTO categories (name, description, slug)
|
116
|
+
VALUES
|
117
|
+
('Technology', 'Posts about technology and programming', 'technology'),
|
118
|
+
('Web Development', 'Frontend and backend web development', 'web-development'),
|
119
|
+
('Database', 'Database design and administration', 'database'),
|
120
|
+
('Career', 'Career advice and professional development', 'career');
|
121
|
+
GO
|
122
|
+
|
123
|
+
INSERT INTO posts (user_id, title, content, status, published_at, view_count, is_featured)
|
124
|
+
VALUES
|
125
|
+
(1, 'Getting Started with SQL Server', 'This post covers the basics of SQL Server...', 'published', GETDATE(), 150, 1),
|
126
|
+
(2, 'Modern CSS Techniques', 'Learn about the latest CSS features...', 'published', GETDATE(), 89, 0),
|
127
|
+
(3, 'Microservices Architecture', 'Building scalable applications with microservices...', 'published', GETDATE(), 234, 1),
|
128
|
+
(1, 'Draft Post', 'This is a draft post...', 'draft', NULL, 0, 0);
|
129
|
+
GO
|
130
|
+
|
131
|
+
INSERT INTO post_categories (post_id, category_id)
|
132
|
+
VALUES
|
133
|
+
(1, 1), (1, 3), -- Technology, Database
|
134
|
+
(2, 1), (2, 2), -- Technology, Web Development
|
135
|
+
(3, 1), (3, 2), -- Technology, Web Development
|
136
|
+
(4, 4); -- Career
|
137
|
+
GO
|
138
|
+
|
139
|
+
INSERT INTO comments (post_id, user_id, content, status)
|
140
|
+
VALUES
|
141
|
+
(1, 2, 'Great introduction to SQL Server!', 'approved'),
|
142
|
+
(1, 3, 'Very helpful, thanks for sharing.', 'approved'),
|
143
|
+
(2, 1, 'Love these CSS tips!', 'approved'),
|
144
|
+
(3, 4, 'Microservices can be complex but worth it.', 'pending');
|
145
|
+
GO
|
146
|
+
|
147
|
+
-- Create some additional indexes for testing index recommendations
|
148
|
+
CREATE INDEX IX_users_email ON users(email);
|
149
|
+
CREATE INDEX IX_users_status ON users(status);
|
150
|
+
CREATE INDEX IX_posts_user_id ON posts(user_id);
|
151
|
+
CREATE INDEX IX_posts_status ON posts(status);
|
152
|
+
CREATE INDEX IX_posts_created_at ON posts(created_at);
|
153
|
+
CREATE INDEX IX_comments_post_id ON comments(post_id);
|
154
|
+
|
155
|
+
PRINT 'Database initialization completed successfully!';
|
156
|
+
PRINT 'Created tables: users, posts, categories, post_categories, comments';
|
157
|
+
PRINT 'Inserted sample data for testing';
|
158
|
+
GO
|
@@ -0,0 +1,154 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
echo "=== SQL Server Database Model Generator Test Suite ==="
|
4
|
+
echo "Waiting for SQL Server to be ready..."
|
5
|
+
|
6
|
+
# Wait for SQL Server to be fully ready
|
7
|
+
sleep 10
|
8
|
+
|
9
|
+
echo "Testing SQL Server connectivity..."
|
10
|
+
ruby -e "
|
11
|
+
require 'tiny_tds'
|
12
|
+
begin
|
13
|
+
client = TinyTds::Client.new(
|
14
|
+
username: ENV['SQLSERVER_USERNAME'],
|
15
|
+
password: ENV['SQLSERVER_PASSWORD'],
|
16
|
+
host: ENV['SQLSERVER_HOST'],
|
17
|
+
port: ENV['SQLSERVER_PORT'].to_i,
|
18
|
+
database: ENV['SQLSERVER_DATABASE']
|
19
|
+
)
|
20
|
+
result = client.execute('SELECT 1 as test')
|
21
|
+
puts '✓ SQL Server connection successful'
|
22
|
+
client.close
|
23
|
+
rescue => e
|
24
|
+
puts \"✗ SQL Server connection failed: #{e.message}\"
|
25
|
+
exit 1
|
26
|
+
end
|
27
|
+
"
|
28
|
+
|
29
|
+
echo
|
30
|
+
echo "=== Testing Database Model Generator with SQL Server ==="
|
31
|
+
echo
|
32
|
+
|
33
|
+
# Test 1: Generate User model
|
34
|
+
echo "1. Testing User model generation..."
|
35
|
+
ruby bin/omg \
|
36
|
+
-T sqlserver \
|
37
|
+
-s $SQLSERVER_HOST \
|
38
|
+
-P $SQLSERVER_PORT \
|
39
|
+
-d $SQLSERVER_DATABASE \
|
40
|
+
-u $SQLSERVER_USERNAME \
|
41
|
+
-p $SQLSERVER_PASSWORD \
|
42
|
+
-t users \
|
43
|
+
-o user_model.rb \
|
44
|
+
-x rspec
|
45
|
+
|
46
|
+
if [ $? -eq 0 ]; then
|
47
|
+
echo "✓ User model generated successfully"
|
48
|
+
echo "Generated files:"
|
49
|
+
ls -la user_model.rb user_model_spec.rb 2>/dev/null || echo " Files not found"
|
50
|
+
else
|
51
|
+
echo "✗ User model generation failed"
|
52
|
+
fi
|
53
|
+
|
54
|
+
echo
|
55
|
+
|
56
|
+
# Test 2: Generate Post model
|
57
|
+
echo "2. Testing Post model generation..."
|
58
|
+
ruby bin/omg \
|
59
|
+
-T sqlserver \
|
60
|
+
-s $SQLSERVER_HOST \
|
61
|
+
-P $SQLSERVER_PORT \
|
62
|
+
-d $SQLSERVER_DATABASE \
|
63
|
+
-u $SQLSERVER_USERNAME \
|
64
|
+
-p $SQLSERVER_PASSWORD \
|
65
|
+
-t posts \
|
66
|
+
-o post_model.rb \
|
67
|
+
-x minitest
|
68
|
+
|
69
|
+
if [ $? -eq 0 ]; then
|
70
|
+
echo "✓ Post model generated successfully"
|
71
|
+
else
|
72
|
+
echo "✗ Post model generation failed"
|
73
|
+
fi
|
74
|
+
|
75
|
+
echo
|
76
|
+
|
77
|
+
# Test 3: Test index recommendations
|
78
|
+
echo "3. Testing index recommendations..."
|
79
|
+
ruby bin/omg \
|
80
|
+
-T sqlserver \
|
81
|
+
-s $SQLSERVER_HOST \
|
82
|
+
-P $SQLSERVER_PORT \
|
83
|
+
-d $SQLSERVER_DATABASE \
|
84
|
+
-u $SQLSERVER_USERNAME \
|
85
|
+
-p $SQLSERVER_PASSWORD \
|
86
|
+
-t comments \
|
87
|
+
-i
|
88
|
+
|
89
|
+
if [ $? -eq 0 ]; then
|
90
|
+
echo "✓ Index recommendations generated successfully"
|
91
|
+
else
|
92
|
+
echo "✗ Index recommendations failed"
|
93
|
+
fi
|
94
|
+
|
95
|
+
echo
|
96
|
+
|
97
|
+
# Test 4: Test auto-detection (should detect SQL Server)
|
98
|
+
echo "4. Testing database type auto-detection..."
|
99
|
+
ruby bin/omg \
|
100
|
+
-s $SQLSERVER_HOST \
|
101
|
+
-P $SQLSERVER_PORT \
|
102
|
+
-d $SQLSERVER_DATABASE \
|
103
|
+
-u $SQLSERVER_USERNAME \
|
104
|
+
-p $SQLSERVER_PASSWORD \
|
105
|
+
-t categories \
|
106
|
+
-o category_model.rb \
|
107
|
+
-x none
|
108
|
+
|
109
|
+
if [ $? -eq 0 ]; then
|
110
|
+
echo "✓ Auto-detection worked (SQL Server detected)"
|
111
|
+
else
|
112
|
+
echo "✗ Auto-detection failed"
|
113
|
+
fi
|
114
|
+
|
115
|
+
echo
|
116
|
+
|
117
|
+
# Show generated model samples
|
118
|
+
echo "=== Generated Model Samples ==="
|
119
|
+
echo
|
120
|
+
|
121
|
+
if [ -f "user_model.rb" ]; then
|
122
|
+
echo "User model (first 30 lines):"
|
123
|
+
head -30 user_model.rb
|
124
|
+
echo "..."
|
125
|
+
echo
|
126
|
+
fi
|
127
|
+
|
128
|
+
if [ -f "post_model.rb" ]; then
|
129
|
+
echo "Post model (first 20 lines):"
|
130
|
+
head -20 post_model.rb
|
131
|
+
echo "..."
|
132
|
+
echo
|
133
|
+
fi
|
134
|
+
|
135
|
+
# Show test files
|
136
|
+
echo "=== Generated Test Files ==="
|
137
|
+
echo
|
138
|
+
|
139
|
+
if [ -f "user_model_spec.rb" ]; then
|
140
|
+
echo "RSpec test file (first 15 lines):"
|
141
|
+
head -15 user_model_spec.rb
|
142
|
+
echo "..."
|
143
|
+
echo
|
144
|
+
fi
|
145
|
+
|
146
|
+
if [ -f "test_post_model.rb" ]; then
|
147
|
+
echo "Minitest file (first 15 lines):"
|
148
|
+
head -15 test_post_model.rb
|
149
|
+
echo "..."
|
150
|
+
echo
|
151
|
+
fi
|
152
|
+
|
153
|
+
echo "=== Test Suite Complete ==="
|
154
|
+
echo "All tests completed. Check the output above for results."
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# Test container for Database Model Generator with SQL Server
|
2
|
+
FROM ruby:3.1-slim
|
3
|
+
|
4
|
+
# Install system dependencies
|
5
|
+
RUN apt-get update && apt-get install -y \
|
6
|
+
curl \
|
7
|
+
gnupg \
|
8
|
+
build-essential \
|
9
|
+
unixodbc-dev \
|
10
|
+
&& rm -rf /var/lib/apt/lists/*
|
11
|
+
|
12
|
+
# Install Microsoft ODBC Driver for SQL Server
|
13
|
+
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - \
|
14
|
+
&& curl https://packages.microsoft.com/config/debian/11/prod.list > /etc/apt/sources.list.d/mssql-release.list \
|
15
|
+
&& apt-get update \
|
16
|
+
&& ACCEPT_EULA=Y apt-get install -y msodbcsql17 \
|
17
|
+
&& rm -rf /var/lib/apt/lists/*
|
18
|
+
|
19
|
+
# Set work directory
|
20
|
+
WORKDIR /app
|
21
|
+
|
22
|
+
# Copy Gemfile and install dependencies
|
23
|
+
COPY Gemfile* ./
|
24
|
+
RUN bundle install
|
25
|
+
|
26
|
+
# Copy application code
|
27
|
+
COPY . .
|
28
|
+
|
29
|
+
# Install tiny_tds gem for SQL Server connectivity
|
30
|
+
RUN gem install tiny_tds
|
31
|
+
|
32
|
+
# Make test script executable
|
33
|
+
RUN chmod +x docker/test/run_tests.sh
|
34
|
+
|
35
|
+
# Default command
|
36
|
+
CMD ["./docker/test/run_tests.sh"]
|
@@ -0,0 +1,56 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
echo "=== SQL Server Model Generator Test ==="
|
4
|
+
echo
|
5
|
+
|
6
|
+
# Check if Docker is available
|
7
|
+
if ! docker --version > /dev/null 2>&1; then
|
8
|
+
echo "❌ Docker is not available"
|
9
|
+
exit 1
|
10
|
+
fi
|
11
|
+
|
12
|
+
echo "✅ Docker is available"
|
13
|
+
|
14
|
+
# Start SQL Server database
|
15
|
+
echo "🚀 Starting SQL Server database with Docker Compose..."
|
16
|
+
docker-compose up -d
|
17
|
+
|
18
|
+
echo "⏳ Waiting for SQL Server to be ready (90 seconds)..."
|
19
|
+
sleep 90
|
20
|
+
|
21
|
+
# Test connection
|
22
|
+
echo "🔍 Testing SQL Server connectivity..."
|
23
|
+
if docker-compose exec -T sqlserver-db /opt/mssql-tools18/bin/sqlcmd -S localhost -U sa -P "TestPassword123!" -C -Q "SELECT @@VERSION" > /dev/null 2>&1; then
|
24
|
+
echo "✅ SQL Server is running and accessible"
|
25
|
+
else
|
26
|
+
echo "❌ SQL Server connectivity test failed"
|
27
|
+
echo "📋 Container logs:"
|
28
|
+
docker-compose logs sqlserver-db | tail -20
|
29
|
+
exit 1
|
30
|
+
fi
|
31
|
+
|
32
|
+
# Create test database if it doesn't exist
|
33
|
+
echo "🏗️ Setting up test database..."
|
34
|
+
docker-compose exec -T sqlserver-db /opt/mssql-tools18/bin/sqlcmd -S localhost -U sa -P "TestPassword123!" -C -Q "
|
35
|
+
IF NOT EXISTS (SELECT name FROM sys.databases WHERE name = 'testdb')
|
36
|
+
BEGIN
|
37
|
+
CREATE DATABASE testdb;
|
38
|
+
END
|
39
|
+
"
|
40
|
+
|
41
|
+
echo "✅ SQL Server is ready for testing"
|
42
|
+
echo "📋 You can now run SQL Server Model Generator tests"
|
43
|
+
echo
|
44
|
+
echo "Connection details:"
|
45
|
+
echo " Host: localhost"
|
46
|
+
echo " Port: 1433"
|
47
|
+
echo " Username: sa"
|
48
|
+
echo " Password: TestPassword123!"
|
49
|
+
echo " Database: testdb"
|
50
|
+
echo
|
51
|
+
echo "To stop the database:"
|
52
|
+
echo " docker-compose down"
|
53
|
+
echo
|
54
|
+
echo "To test model generation:"
|
55
|
+
echo " cd ../../"
|
56
|
+
echo " bin/dmg --type sqlserver --server localhost --port 1433 --user sa --password TestPassword123! --database testdb --table <table_name>"
|