Merge branch 'order-implementations' into 'master'

Order implementations

See merge request pastebin.run/server!97
This commit is contained in:
Konrad Borowski 2019-12-25 16:50:19 +00:00
commit 2b2792145b
5 changed files with 26 additions and 7 deletions

View File

@ -0,0 +1 @@
ALTER TABLE implementations DROP COLUMN ordering;

View File

@ -0,0 +1,5 @@
TRUNCATE implementation_wrappers;
DELETE FROM implementations;
ALTER TABLE implementations ADD COLUMN ordering int NOT NULL;
ALTER TABLE implementations ADD CONSTRAINT implementations_language_id_ordering_key UNIQUE (language_id, ordering);

View File

@ -86,11 +86,14 @@ pub fn run(connection: &Connection) -> Result<(), Box<dyn Error>> {
.execute(connection)?;
}
}
for Implementation {
label,
identifier: implementation_identifier,
wrappers,
} in implementations
for (
i,
Implementation {
label,
identifier: implementation_identifier,
wrappers,
},
) in (1..).zip(implementations)
{
languages::table
.filter(languages::identifier.eq(&languages_identifier))
@ -98,16 +101,24 @@ pub fn run(connection: &Connection) -> Result<(), Box<dyn Error>> {
languages::language_id,
label.as_sql::<Text>(),
implementation_identifier.as_sql::<Text>(),
i.as_sql::<Integer>(),
))
.insert_into(implementations::table)
.into_columns((
implementations::language_id,
implementations::label,
implementations::identifier,
implementations::ordering,
))
.on_conflict((
implementations::language_id,
implementations::identifier,
))
.on_conflict((implementations::language_id, implementations::identifier))
.do_update()
.set(implementations::label.eq(&label))
.set((
implementations::label.eq(&label),
implementations::ordering.eq(i),
))
.execute(connection)?;
for (
i,

View File

@ -74,6 +74,7 @@ pub fn api_language(
let implementations = implementations::table
.select((implementations::implementation_id, implementations::label))
.filter(implementations::language_id.eq(language.id))
.order(implementations::ordering)
.load(&connection)
.map_err(warp::reject::custom)?;
let implementation_wrappers = ImplementationWrapper::belonging_to(&implementations)

View File

@ -4,6 +4,7 @@ table! {
language_id -> Int4,
identifier -> Text,
label -> Text,
ordering -> Int4,
}
}