Comments (6)
The issue seems to be that authored_at is not converted to milliseconds before being converted to a Date.
Suggested patch below. Please note that the test case fails after this update -- I'm not a Scala programmer, so I wasn't sure how to fix the test.
diff --git a/src/main/scala/com/chrisomeara/pillar/Parser.scala b/src/main/scala/com/chrisomeara/pillar/Parser.scala
index 4f7a550..de196b4 100644
--- a/src/main/scala/com/chrisomeara/pillar/Parser.scala
+++ b/src/main/scala/com/chrisomeara/pillar/Parser.scala
@@ -21,15 +21,15 @@ class PartialMigration {
if (description.isEmpty) errors("description") = "must be present"
if (authoredAt.isEmpty) errors("authoredAt") = "must be present"
- if (!authoredAt.isEmpty && authoredAtAsLong < 1) errors("authoredAt") = "must be a number greater than zero"
+ if (!authoredAt.isEmpty && authoredAtAsMillis < 1) errors("authoredAt") = "must be a number greater than zero"
if (up.isEmpty) errors("up") = "must be present"
if (!errors.isEmpty) Some(errors.toMap) else None
}
- def authoredAtAsLong: Long = {
+ def authoredAtAsMillis: Long = {
try {
- authoredAt.toLong
+ authoredAt.toLong * 1000
} catch {
case _:NumberFormatException => -1
}
@@ -80,11 +80,11 @@ class Parser {
inProgress.down match {
case Some(downLines) =>
if (downLines.isEmpty) {
- Migration(inProgress.description, new Date(inProgress.authoredAtAsLong), inProgress.up.mkString("\n"), None)
+ Migration(inProgress.description, new Date(inProgress.authoredAtAsMillis), inProgress.up.mkString("\n"), None)
} else {
- Migration(inProgress.description, new Date(inProgress.authoredAtAsLong), inProgress.up.mkString("\n"), Some(downLines.mkString("\n")))
+ Migration(inProgress.description, new Date(inProgress.authoredAtAsMillis), inProgress.up.mkString("\n"), Some(downLines.mkString("\n")))
}
- case None => Migration(inProgress.description, new Date(inProgress.authoredAtAsLong), inProgress.up.mkString("\n"))
+ case None => Migration(inProgress.description, new Date(inProgress.authoredAtAsMillis), inProgress.up.mkString("\n"))
}
}
}
diff --git a/src/test/scala/com/chrisomeara/pillar/ParserSpec.scala b/src/test/scala/com/chrisomeara/pillar/ParserSpec.scala
index 90679f8..b1daa6c 100644
--- a/src/test/scala/com/chrisomeara/pillar/ParserSpec.scala
+++ b/src/test/scala/com/chrisomeara/pillar/ParserSpec.scala
@@ -17,7 +17,8 @@ class ParserSpec extends FunSpec with BeforeAndAfter with ShouldMatchers {
it("assigns authoredAt") {
val resource = new FileInputStream(migrationPath)
- Parser().parse(resource).authoredAt should equal(new Date(1370023262))
+ val expected = new Date(1370023262000L).toString
+ Parser().parse(resource).authoredAt should equal(expected)
}
it("assigns description") {
@@ -101,4 +102,4 @@ class ParserSpec extends FunSpec with BeforeAndAfter with ShouldMatchers {
}
}
}
-}
\ No newline at end of file
+}
from pillar.
This patch is also needed so that -t works, after my changes above:
diff --git a/src/main/scala/com/chrisomeara/pillar/cli/CommandLineConfiguration.scala b/src/main/scala/com/chrisomeara/pillar/cli/CommandLineConfiguration.scala
index d074aba..709d49d 100644
--- a/src/main/scala/com/chrisomeara/pillar/cli/CommandLineConfiguration.scala
+++ b/src/main/scala/com/chrisomeara/pillar/cli/CommandLineConfiguration.scala
@@ -24,7 +24,10 @@ object CommandLineConfiguration {
directory
}
val environmentOption = parser.option[String](List("e", "environment"), "env", "environment")
- val timeStampOption = parser.option[Long](List("t", "time-stamp"), "time", "The migration time stamp")
+ val timeStampOption = parser.option[Long](List("t", "time-stamp"), "time", "The migration time stamp") {
+ (timeStamp, _) =>
+ java.lang.Long.parseLong(timeStamp) * 1000
+ }
parser.parse(arguments)
from pillar.
Hi,
The implementation is correct perl -e 'print gmtime(1420779600)."\n";' takes a time in seconds but java.util.date takes milliseconds so authoredAt 1420779600
scala> val x = new java.util.Date(1420779600)
x: java.util.Date = Sat Jan 17 11:39:39 GMT 1970
so just add three zeros to your timestamp
scala> val x = new java.util.Date(1420779600000L)
x: java.util.Date = Fri Jan 09 05:00:00 GMT 2015
By the way I've created a fork of this project that merges in the outstanding pull requests on a branch called patch and also adds an authoredAtDate field where you can specify your date as 2015-01-09 05:00:00, using timestamp was becoming annoying. Version number was bumped to 2.0.2
see https://github.com/smr-co-uk/pillar/tree/patch
Peter
from pillar.
Are you saying that the authoredAt timestamp in the migration file is supposed to be in milliseconds?
None of the examples of authoredAt in the documentation are in milliseconds.
authoredAtDate sounds like a useful addition. :)
Thanks, Rich
from pillar.
Yes.
I know, its not ideal, but doesn’t make any difference in practice though, but it makes it easier for humans to understand.
Yes, much easier than trying to figure out a millisecond timestamp if you want to know what date it was authored on.
Peter
On 4 Mar 2015, at 15:04, Richard Dawe [email protected] wrote:
Are you saying that the authoredAt timestamp in the migration file is supposed to be in milliseconds?
None of the examples of authoredAt in the documentation are in milliseconds.
authoredAtDate sounds like a useful addition. :)
Thanks, Rich
—
Reply to this email directly or view it on GitHub #21 (comment).
from pillar.
I'll open a ticket to fix up the documentation instead. Thanks!
from pillar.
Related Issues (20)
- How to ignore applied scripts? HOT 5
- Failing to install pillar using Maven
- Update documentation to note that authoredAt timestamp is in milliseconds HOT 5
- Allow to specify consistency levels for reads/writes of applied migrations HOT 1
- Support authenticated Cassandra HOT 2
- Implement reversal of migration as a command line option HOT 2
- problem with cassandra 3 HOT 7
- Link to Galeria-Kaufhof/pillar fork / joint development HOT 5
- Add zip file packaging
- Provide SLF4J binding when running command line application
- Applied migration table is not ordered by the correct authored_at time
- When using multi-stage migrations, a failure in stage 2 leaves stage 1 committed, even with a proper down statement
- Build for Scala 2.12 HOT 3
- missing EOF at 'CREATE' when running multiple stages migration script. HOT 3
- Migration fails silently when no directory with datastore name is found
- Multi-stage queries fail on C* 3.0.9
- support copy command
- Config file has to be in install location
- Build for Scala 2.13
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pillar.