Domain_Handler 0.0.18 → 0.0.20

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/domain_handler.rb +41 -33
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c75b8f5785bb4b279b979b4a9fe3675dad155b959ebe5de791ada40a7b192513
4
- data.tar.gz: 751dac8c75651374e8764a698e3c3b60cd5ab58c6c68920c4598eb3cdf959e2d
3
+ metadata.gz: c53879f1c2f12ad82f245076a2528c5abaf26295186664a167db16c043b0c239
4
+ data.tar.gz: fb2f7078d3a054cf77a35536f66212980cad252856f38c0af0ca86a6f3456fd9
5
5
  SHA512:
6
- metadata.gz: 37d2b0091a16fdf0f242b49db943c23c9e9fa995711add16c8e8467ed2641cdff2550abd7c1d31ba9ab0f460e3e0b932bd23cbf6f44cc8fc723c4883ddc23722
7
- data.tar.gz: 570f5850cadd4cd2a8bc263006f2dfcee0467bbf3f15059205cac2d9afbaf37f9671bb55738311fd59b43bc7f5447121c243a275997ca2ea315693bd147e7cb1
6
+ metadata.gz: 38c94b6cf43d316e5e05f552c3dc99d70fdf635cedc4332b937491abf177ab6dc09de6cf33ce373d878e7ad58cad64813bf806dbbacd905179c9d81a48f1f6a1
7
+ data.tar.gz: 93c6b2ec3ce6e0b2743db5f8876acd57f42d157d5c58bbd2bec3f0fbc87d02981cf1b0b7e048460786f1793a98855369699864f0926d17c662858f42cc0202d2
@@ -68,40 +68,48 @@ class DomainHandler
68
68
  )
69
69
  end
70
70
 
71
- def self.generate_migration
72
- require 'active_record'
73
- require 'active_record/migration'
74
- # Connect to your database
75
- ActiveRecord::Base.establish_connection(
76
- database: ENV['DB_NAME'],
77
- username: ENV['DB_USER'],
78
- password: ENV['DB_PWD'],
79
- host: 'http://localhost:5432',
80
- adapter: ENV['DB_ADAPTER']
81
- )
82
-
83
- timestamp = Time.now.utc.strftime("%Y%m%d%H%M%S")
84
- migration_file = "db/migrate/#{timestamp}_create_domains.rb"
85
-
86
- migration_context = ActiveRecord::MigrationContext.new(migration_file, CreateDomains)
71
+ def self.create_migration
72
+ migration_name = 'create_domains'
73
+
74
+ # Generate a timestamp to use as the migration version
75
+ timestamp = Time.now.strftime('%Y%m%d%H%M%S')
76
+
77
+ # Generate the migration file name
78
+ migration_file_name = "#{timestamp}_#{migration_name}.rb"
79
+
80
+ # Specify the migration class name
81
+ migration_class_name = migration_name.camelize
82
+
83
+ # Specify the migration file path
84
+ migration_file_path = Rails.root.join('db', 'migrate', migration_file_name)
85
+ # Create the migration file
86
+ File.open(migration_file_path, 'w') do |file|
87
+ file.write("class #{migration_class_name} < ActiveRecord::Migration[6.1]\n")
88
+ file.write(" def change\n")
89
+ file.write(" create_table :domains, id: false, primary_key: :domain_id do |t|\n")
90
+ file.write(" # Define your table columns here\n")
91
+ file.write(" t.references :shop, foreign_key: true\n")
92
+ file.write(" t.string :host, null: false, default: ''\n")
93
+ file.write(" t.string :localization\n")
94
+ file.write(" t.string :market_web_presence\n")
95
+ file.write(" t.boolean :ssl_enabled, null: false\n")
96
+ file.write(" t.string :url\n")
97
+ file.write(" t.string :domain_id\n")
98
+ file.write(" t.index :domain_id, unique: true\n")
99
+ file.write(" t.timestamps\n")
100
+ file.write(" end\n")
101
+ file.write(" end\n")
102
+ file.write("end\n")
103
+ end
87
104
 
88
- # Generate the migration file using the create_table method
89
- migration_context.migrate(target_version = nil)
105
+ model_name = 'domain.rb'
106
+ model_file_path = Rails.root.join('app', 'models', model_name)
107
+ File.open(model_file_path, 'w') do |file|
108
+ file.write("class Domain < ApplicationRecord \n")
109
+ file.write(" self.primary_key = :domain_id \n")
110
+ file.write(" belongs_to :shop \n")
111
+ file.write("end \n")
112
+ end
90
113
  end
91
114
  end
92
115
 
93
- class CreateDomains < ActiveRecord::Migration[5.0]
94
- def change
95
- create_table :domains, id: false, primary_key: :domain_id do |t|
96
- t.references :shop, foreign_key: true
97
- t.string :host, null: false, default: ''
98
- t.string :localization
99
- t.string :market_web_presence
100
- t.boolean :ssl_enabled, null: false
101
- t.string :url
102
- t.string :domain_id
103
- t.index :domain_id, unique: true
104
- t.timestamps
105
- end
106
- end
107
- end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: Domain_Handler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.18
4
+ version: 0.0.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arun Sahu