Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
whaleback
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open-source
whaleback
Commits
c63eeed5
Commit
c63eeed5
authored
6 years ago
by
ivan Lan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add migrations generator
parent
1896df9a
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
57 additions
and
0 deletions
+57
-0
1_create_media_objs_and_media_attachments.rb
db/migrate/1_create_media_objs_and_media_attachments.rb
+19
-0
migrations_generator.rb
lib/generators/whaleback/migrations_generator.rb
+2
-0
whaleback.rb
lib/whaleback.rb
+1
-0
migrations_generator.rb
lib/whaleback/generators/migrations_generator.rb
+35
-0
No files found.
db/migrate/1_create_media_objs_and_media_attachments.rb
0 → 100644
View file @
c63eeed5
class
CreateMediaObjsAndMediaAttachments
<
ActiveRecord
::
Migration
[
5.1
]
def
change
create_table
:media_objs
do
|
t
|
t
.
attachment
:file
t
.
string
:type
t
.
references
:creator
,
polymorphic:
true
t
.
timestamps
end
create_table
:media_attachments
do
|
t
|
t
.
string
:column_name
t
.
references
:attached
,
polymorphic:
true
t
.
references
:obj
t
.
timestamps
end
end
end
This diff is collapsed.
Click to expand it.
lib/generators/whaleback/migrations_generator.rb
0 → 100644
View file @
c63eeed5
require
'whaleback/generators/migrations_generator'
\ No newline at end of file
This diff is collapsed.
Click to expand it.
lib/whaleback.rb
View file @
c63eeed5
require
"whaleback/version"
require
'paperclip'
module
Whaleback
# Your code goes here...
...
...
This diff is collapsed.
Click to expand it.
lib/whaleback/generators/migrations_generator.rb
0 → 100644
View file @
c63eeed5
require
'rails/generators/migration'
module
Whaleback
module
Generators
class
MigrationsGenerator
<
Rails
::
Generators
::
Base
include
Rails
::
Generators
::
Migration
desc
'Copy whaleback migrations to your application.'
def
self
.
next_migration_number
(
dir
)
sleep
1
Time
.
now
.
utc
.
strftime
(
"%Y%m%d%H%M%S"
)
end
source_root
File
.
expand_path
(
"../../../../db/migrate"
,
__FILE__
)
def
copy_migrations
# Use sort() to order the migrations by seq
# Use [2..-1] to delete the seq
Dir
[
File
.
join
(
self
.
class
.
source_root
,
'*.rb'
)
].
sort
.
each
{
|
f
|
copy_migration
File
.
basename
(
f
,
'.rb'
)
}
end
protected
def
copy_migration
(
filename
)
if
self
.
class
.
migration_exists?
(
"db/migrate"
,
"
#{
filename
[
2
..-
1
]
}
"
)
say_status
(
"skipped"
,
"Migration
#{
filename
[
2
..-
1
]
}
already exists"
)
else
migration_template
"
#{
filename
}
.rb"
,
"db/migrate/
#{
filename
[
2
..-
1
]
}
.rb"
end
end
end
end
end
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment