rmvc 3.2.2 → 3.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rmvc/migrations.rb +32 -8
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5b9a00c8b673dc9d20c8b70a9eb930333680065d
|
4
|
+
data.tar.gz: aa7ca06e4233ba40712f5044ddac6d81689c5a6d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ac91805f0be4f05220af223e5a11d6b254e028b236aac62c7457de8e6198abbb7275e0e09c68037563e621602531a40b4984cd2c3cfeb5a1e90b5098cfd9aed
|
7
|
+
data.tar.gz: 9aadac152c713ca89d92246a75457227240595e5f3570a884524541d265b6f3d82d70a80eadd974d1ec99d983c534c2299e0ccc14a417a72e3965907b5ce39f6
|
data/lib/rmvc/migrations.rb
CHANGED
@@ -1,17 +1,29 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require 'colorize'
|
3
3
|
require 'sqlite3'
|
4
|
+
|
5
|
+
# We're in the RMVC module.
|
4
6
|
module RMVC
|
5
|
-
|
7
|
+
|
8
|
+
# Class: Migration
|
9
|
+
# Contains a RMVC migration
|
6
10
|
class Migration
|
7
|
-
|
11
|
+
|
12
|
+
# @dbr: resource referencing to the database connection
|
8
13
|
attr_accessor :dbr
|
14
|
+
|
15
|
+
# Method: constructor
|
16
|
+
# Arguments: database (string) - name of the migration's database
|
17
|
+
# Starts the @dbr connection, creates it if the file doesn't exist
|
9
18
|
def initialize(database)
|
19
|
+
|
10
20
|
if File.exists?("./db/" + database + ".db")
|
11
21
|
puts "database #{database} already exists. opening...".green
|
12
22
|
@dbr = SQLite3::Database.open("./db/" + database + ".db")
|
23
|
+
|
13
24
|
else
|
14
25
|
puts "database #{database} not found. creating database...".yellow
|
26
|
+
|
15
27
|
begin
|
16
28
|
@dbr = SQLite3::Database.new("./db/" + database + ".db")
|
17
29
|
puts "database #{database} successfully created.".green
|
@@ -19,14 +31,17 @@ module RMVC
|
|
19
31
|
puts "couldn't create database. aborting...".red
|
20
32
|
exit
|
21
33
|
end
|
34
|
+
|
22
35
|
end
|
23
36
|
end
|
24
37
|
|
25
|
-
#
|
38
|
+
# Method: create_table
|
39
|
+
# Arguments: table (string)
|
40
|
+
# Creates a table in the database
|
26
41
|
def create_table(table)
|
27
42
|
puts "attempting to create table #{table}..."
|
28
43
|
begin
|
29
|
-
tt = @dbr.prepare("CREATE TABLE #{table}(id
|
44
|
+
tt = @dbr.prepare("CREATE TABLE #{table}(id INTEGER PRIMARY KEY);")
|
30
45
|
ee = tt.execute
|
31
46
|
puts "table created correctly.".green
|
32
47
|
rescue
|
@@ -35,7 +50,9 @@ module RMVC
|
|
35
50
|
end
|
36
51
|
end
|
37
52
|
|
38
|
-
#
|
53
|
+
# Method: drop_table
|
54
|
+
# Arguments: table (string)
|
55
|
+
# Removes a table of the database
|
39
56
|
def drop_table(table)
|
40
57
|
puts "attempting to drop table #{table}..."
|
41
58
|
begin
|
@@ -47,7 +64,10 @@ module RMVC
|
|
47
64
|
end
|
48
65
|
end
|
49
66
|
|
50
|
-
#
|
67
|
+
# Method: add_column
|
68
|
+
# Arguments: table(string) - table name
|
69
|
+
# cname(string) - name of the column
|
70
|
+
# type(:text, :num, string) - type of the column
|
51
71
|
def add_column(table, cname, type)
|
52
72
|
if type.to_s == "text"
|
53
73
|
puts "attempting to create text column #{cname} at #{table}..."
|
@@ -59,6 +79,7 @@ module RMVC
|
|
59
79
|
puts "error while adding column #{cname} to #{table}".red
|
60
80
|
exit
|
61
81
|
end
|
82
|
+
|
62
83
|
elsif type.to_s == "num"
|
63
84
|
puts "attempting to create numerical column #{cname} at #{table}..."
|
64
85
|
begin
|
@@ -69,6 +90,7 @@ module RMVC
|
|
69
90
|
puts "error while adding column #{cname} to #{table}".red
|
70
91
|
exit
|
71
92
|
end
|
93
|
+
|
72
94
|
else
|
73
95
|
puts "attempting to create custom (#{type.to_s}) column #{cname} at #{table}..."
|
74
96
|
begin
|
@@ -82,8 +104,10 @@ module RMVC
|
|
82
104
|
end
|
83
105
|
end
|
84
106
|
|
85
|
-
#
|
86
|
-
#
|
107
|
+
# Method: insert
|
108
|
+
# Arguments: table(string) - table name
|
109
|
+
# columns([string, ]) - columns where data will be inserted
|
110
|
+
# values([string|int|other, ]) - values to be inserted
|
87
111
|
def insert(table, columns, values)
|
88
112
|
puts "attempting to insert values into #{table}..."
|
89
113
|
begin
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rmvc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.2.
|
4
|
+
version: 3.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- unrar
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-08-
|
11
|
+
date: 2015-08-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|